I have a file that looks like this:Heading1,Heading2value1,value2And another one that looks like this:Row1Row2How can I combine the two to become:Row1,Heading1,Heading2Row2,value1,value2Effectively appending a column in the place of the first column?
Append first column to file
text processing;command line;awk;sed;paste
Job for paste:paste -d, f2.txt f1.txt-d, sets the delimiter as , (instead of tab)With awk:awk 'BEGIN {FS=OFS=,} NR==FNR {a[NR]=$0; next} {print a[FNR], $0}' f2.txt f1.txt BEGIN {FS=OFS=,} sets the input and output field separators as ,NR==FNR {a[NR]=$0; next}: for first file (f2.txt), we are saving the record number as key to an associative array (a) with values being the corresponding record {print a[FNR], $0}: for second file, we are just printing the record with the value of record number-ed key from a prependedExample:% cat f1.txt             Heading1,Heading2value1,value2% cat f2.txt             Row1Row2% paste -d, f2.txt f1.txtRow1,Heading1,Heading2Row2,value1,value2% awk 'BEGIN {FS=OFS=,} NR==FNR {a[NR]=$0; next} {print a[FNR], $0}' f2.txt f1.txt Row1,Heading1,Heading2Row2,value1,value2