2

I have file test1 with lines like this:

A B C
D E F
...

and I want to have file test2 with lines:

DDD EEE FFF A
DDD EEE FFF D
...

where A and D are copied from first column of test1 file after phrase DDD EEE FFF to test2 file

I started like below,

cat test1 | echo "DDD EEE FFF " `awk '{print $1}'` > test2

but of course it only adds phrase DDD EEE FFF once and then appends A, D to it which is not what I want

DDD EEE FFF  A D
5

First remove everything from the first whitespace on, then add your phrase to the beginning:

sed 's/ .*//;s/^/DDD EEE FFF /' test1
  • grateful for both , unfortunately can only reward one.. – irom Sep 11 '17 at 17:00
  • 1
    @irom Then reward Philippos, he was first to answer. – xhienne Sep 11 '17 at 17:05
6

Philippos' answer is good. If you are more comfortable with awk, try this:

awk '{print "DDD EEE FFF " $1}' test1 > test2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.