Reputation: 311
adding extra lines after each line in a file
I need help for the following task for around 1000 lines file.
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.
Upvotes: 1
Views: 107
Reputation: 247210
Use whitespace or dots as the delimiter to extract the word you need:
awk -F '[[:blank:].]+' '{print; print "mv complex.*", $4}' filename
Upvotes: 2
Reputation: 290505
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
Upvotes: 3
Reputation:
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):
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
Upvotes: 3