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

2 Answers 2

6

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

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .