[英]Problems with shell script (sed) in bash
I am attempting to run the following script 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
Each line has been tested separately and functions as it should, except when put together into a script. 每行都经过了单独的测试,并可以正常运行,除非放到脚本中。
The first file seems to be just fine. 第一个文件似乎很好。 The next 4 files are blank.
接下来的4个文件为空。 Then the next 2 files are good.
那么接下来的两个文件是好的。 This keeps up at seemingly random intervals throughout the 550 files that I need to run this on.
在我需要对其运行的550个文件中,这似乎保持随机的间隔。
Any Ideas? 有任何想法吗?
Thanks. 谢谢。
sed -i -b '/^.$/,$d' *.txt
##Deletes all blank lines and text following and including the first blank line
You probably mean 你可能是说
sed -i -b '/^$/,$d' *.txt
Even further 更深入
sed -i -b '/^[[:blank:]]*$/,$d' *.txt
Which would include those lines with only spaces. 这将包括那些只有空格的行。
On a test, this command 在测试中,此命令
(echo a; echo b; echo; echo b; echo; echo; echo c; echo d) | sed '/^$/,$d'
Shows 展会
a
b
While this command 当这个命令
(echo a; echo b; echo; echo b; echo; echo; echo c; echo d) | sed '/^.$/,$d'
Shows nothing. 什么也没显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.