[英]Problems with shell script (sed) in bash
我正在嘗試在bash中運行以下腳本:
#! /bin/Bash
cp '../Text_Files_Backups/'*.txt .
sed -i '1,/Ref/d' *.txt
##Deletes all lines from the begining of file up to and including the line that includes the text 'Ref'
##
sed -i -b '/^.$/,$d' *.txt
##Deletes all blank lines and text following and including the first blank line
sed -i 's/\([(a-zA-Z) ]\)\([(1-9)][(0-9)][ ][ ]\)/\1\n\2/g' *.txt
##Searches document for any instance of a letter character immediately followed by a 2 digit number ##immediately followed by 2 blank spaces
## <or>
##a blank space immediately followed by a 2 digit number immediately followed by 2 blank spaces
## and inserts a new line immediately prior to the 2 digit number
exit
每行都經過了單獨的測試,並可以正常運行,除非放到腳本中。
第一個文件似乎很好。 接下來的4個文件為空。 那么接下來的兩個文件是好的。 在我需要對其運行的550個文件中,這似乎保持隨機的間隔。
有任何想法嗎?
謝謝。
sed -i -b '/^.$/,$d' *.txt
##Deletes all blank lines and text following and including the first blank line
你可能是說
sed -i -b '/^$/,$d' *.txt
更深入
sed -i -b '/^[[:blank:]]*$/,$d' *.txt
這將包括那些只有空格的行。
在測試中,此命令
(echo a; echo b; echo; echo b; echo; echo; echo c; echo d) | sed '/^$/,$d'
展會
a
b
當這個命令
(echo a; echo b; echo; echo b; echo; echo; echo c; echo d) | sed '/^.$/,$d'
什么也沒顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.