简体   繁体   English

在文件的每一行之后添加额外的行

[英]adding extra lines after each line in a file

adding extra lines after each line in a file 在文件的每一行之后添加额外的行

I need help for the following task for around 1000 lines file. 我需要大约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
    ...

I know following command can add the new line and first part which makes the output like below. 我知道以下命令可以添加新行和第一部分,从而使输出如下所示。

    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.* 
    ...

How to do the rest? 剩下的怎么办? Thanks a lot in advance. 非常感谢。

My attempt: 我的尝试:

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

or using && between ./create.pl and mv (since mv is likely needed only when ./create.pl is correctly executed): 或在./create.plmv之间使用&& (因为仅当正确执行./create.pl时才可能需要mv):

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

which gives: 这使:

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

You were nearly there: 您快到了:

$ 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

使用空格或点作为分隔符以提取所需的单词:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM