3

I need to combine contents of 2 text files, word by word.

The script takes every word from file 1 and combines with file 2. it adds all the combined words in file 3.

Example:

File1        File2         
WordA1       WordB1
WordA2       WordB2
WordA3       WordB3

Output: WordA1 WordB1 WordA2 WordB2 WordA3 WordB3

How can I accomplish this? Is this possible with the cat command?

Robotnik
  • 2,645
sam
  • 31

3 Answers3

3

Try doing this :

paste file1 file2

If you want it on only one like :

paste file1 file2 | sed -n '2,$p' | paste -sd ' '
Gilles Quénot
  • 4,475
  • 1
  • 30
  • 28
1
cat file1 file2 > outputfile.txt
Frank Thomas
  • 37,476
0
[max@localhost ~]$ cat file1
wordA1
wordA2
wordA3
[max@localhost ~]$ cat file2
wordB1
wordB2
wordB3
[max@localhost ~]$ paste -s file1 file2 > file3
[max@localhost ~]$ cat file3 
wordA1  wordA2  wordA3
wordB1  wordB2  wordB3
max
  • 4,163