File1 + (File2 - first line)> File3

I have two csv / text files that I would like to join. Both contain the same first line. I am trying to figure out how to use sed and cat to create a merged file, but with only one copy of the first line. And I have time with syntax. Any help would be greatly appreciated: -D! Thanks, Andrew

+5
source share
4 answers

This would merge the files data1.txtand data2.txtfile merged.txt, skipping the first line of data2.txt. It uses awk if you are ok:

(cat data1.txt; awk 'NR>1' data2.txt) > merged.txt

awk adds all lines with line number> 1 from file data2.txtto file merged.txt.

NR - awk, . NR > 1 , awk .

data1.txt , ( ) :

awk 'NR>1' data2.txt >> data1.txt
+4

awk:

awk 'NR==FNR || FNR>1' file1.txt file2.txt .. fileN.txt

.

+4

, :

( cat file1.txt ; tail -n +2 file2.txt ) > file3.txt

, , : , , , .

+2

 '1 d' 2

1

sed '1 d' file2 >> file1
+1

All Articles