-4

I have file1 which has data as follows:

url1
url2
url3
url4
.
.
.

file2 has data as below:

xml1
xml2 
xml3
.
.
.

I want to merge these two files and the merged file say file3 should look below:

url1
xml1
url2
xml2
url3
xml3
url4
xml4
whoan
  • 8,143
  • 4
  • 39
  • 48
Jams
  • 3,769
  • 3
  • 18
  • 13
  • Is this the real data? Could you please add an example of the real data? Are these strings always separated by a whitespace? – reto Dec 29 '14 at 19:13
  • While you're editing your question with real data, please also indicate if you expect there will there always be an xml{n} for each url{n}? Good luck. – shellter Dec 29 '14 at 19:20
  • they are some http url's always in both the files.. like http://google.com/ab/bc http://google.com/cd/de – Jams Dec 29 '14 at 19:20
  • file1: http://google.com/studio/image http://google.com/studio/image1 file2: http://yahoo.com/standard/img http://yahoo.com/standard/img1 merged file say file3 should be http://google.com/studio/image http://yahoo.com/standard/img http://google.com/studio/image1 http://yahoo.com/standard/img1 – Jams Dec 29 '14 at 19:30
  • http://unix.stackexchange.com/questions/26601/how-to-read-from-two-input-files-using-while-loop – ptierno Dec 29 '14 at 19:31

1 Answers1

1

This should do:

while read -r file1 && read -r file2 <&3; do
  echo "$file1"; echo "$file2"
done <file1.txt 3<file2.txt
Amit
  • 19,780
  • 6
  • 46
  • 54