1

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 つのファイルは空白です。次に、次の 2 つのファイルは良好です。これは、これを実行する必要がある 550 個のファイル全体で一見ランダムな間隔で維持されます。

何か案は?

ありがとう。

4

1 に答える 1

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'

何も表示されません。

于 2013-09-10T18:19:01.593 に答える