[英]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.