0

This question already has an answer here:

Is there a way to copy the first line in a text file to the end of every line? - could include copying line 1 to the end of line 1 if it simplifies things.

 I have:

 __1
 2
 3

 I want:


 1
 2__1
 3__1

 or 

 1__1
 2__1
 3__1

It has to be easily modified to handle multiple files.

Any suggestions?

Big thanks.

marked as duplicate by don_crissti, Community Mar 12 '17 at 21:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Thanks I was searching for every line and the above duplicate post used each - thanks for finding it. – speld_rwong Mar 12 '17 at 21:28
0

With awk:

To append the first line of each file to every line of the same file:

awk 'FNR == 1 {suffix=$0} {print $0suffix}' file1 file2 file3

To leave the first line alone:

awk 'FNR == 1 {suffix=$0} FNR != 1 {print $0suffix}' file1 file2 file3

To append the first line of file1 to every line of several files:

awk 'NR==1' {suffix=$0} {print $0suffix} file1 file2 file3

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