我试图在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个文件中保持看似随机的间隔。
任何想法?
感谢。
答案 0 :(得分:2)
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'
什么都不显示。