2013-06-27 57 views
1

在文件中的每行之後添加額外的行在文件中的每行之後添加額外的行

我需要大約1000行文件的以下任務的幫助。

INPUT

./create.pl  1eaj.out 
    ./create.pl  1ezg.out 
    ./create.pl  1f41.out 
    ... 

OUTPUT

./create.pl  1eaj.out 
    mv complex.* 1eaj 
    ./create.pl  1ezg.out 
    mv complex.* 1ezg 
    ./create.pl  1f41.out 
    mv complex.* 1f41 
    ... 

我知道下列命令可以添加新的線和第一部分,其使輸出像的下方。

awk ' {print;} NR % 1 == 0 { print "mv complex.* "; }' 

    ./create.pl  1eaj.out 
    mv complex.* 
    ./create.pl  1ezg.out 
    mv complex.* 
    ./create.pl  1f41.out 
    mv complex.* 
    ... 

剩下的事怎麼辦? 非常感謝。

+0

。 – Bernhard

回答

3

我嘗試:

sed -n 's/^\(\.\/create\.pl\)\s*\(.*\)\.out$/\1 \2.out\nmv complex.* \2/p' s.txt 

,或者使用與mv&&之間./create.pl(因爲很可能只需要MV時正確執行./create.pl):

sed -n 's/^\(\.\/create\.pl\)\s*\(.*\)\.out$/\1 \2.out \&\& mv complex.* \2/p' s.txt 

其給出:

./create.pl 1eaj.out && mv complex.* 1eaj 
./create.pl 1ezg.out && mv complex.* 1ezg 
./create.pl 1f41.out && mv complex.* 1f41 
+0

哇skwllsp。非常感謝。它工作正常。 – user2176228

3

你幾乎沒有在這裏:

$ awk '{print $1, $2, "\nmv complex.*", $2}' file 
./create.pl 1eaj.out 
mv complex.* 1eaj.out 
./create.pl 1ezg.out 
mv complex.* 1ezg.out 
./create.pl 1f41.out 
mv complex.* 1f41.out 
2

使用空格或點作爲分隔符來提取您需要的一句話:你可以考慮寫一個循環來達到你所需要的

awk -F '[[:blank:].]+' '{print; print "mv complex.*", $4}' filename 
相關問題