0

I have a two files. File 1 looks like this:

a 1 b 6 c 8

The second file is:

a 2 b 4.5 c 3.8

I want to merge file 1 and file 2 in a way that always outputs:

a 1 a 2 b 6 b 4.5 c 8 c 3.8

Philip Kirkbride
  • 9,816
  • 25
  • 95
  • 167
Endora
  • 1
  • `awk '{print; if(getline < "file2") print}' file1` from [http://stackoverflow.com/questions/4011814/how-to-interleave-lines-from-two-text-files](http://stackoverflow.com/questions/4011814/how-to-interleave-lines-from-two-text-files) – Emilio Galarraga Feb 25 '17 at 13:53

2 Answers2

0

According to this Stack Overflow answer, you can do:

awk '{print; if(getline < "file2") print}' file1
Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
Emilio Galarraga
  • 1,264
  • 12
  • 19
0

Depending on how you want them to be interleaved, you could also try cat file1.txt file2.txt | sort > files.txt