Little Girl's Mostly Linux Blog

CombineTwoTextFiles

Combine two text files

This page was last updated on October 15, 2009.

Side By Side

  • Type this command in a terminal window to have the contents displayed side by side:
  • paste file1 file2 > combinedfile
    • Example:
    • Contents of file1 Contents of file2 Contents of combinedfile
      1
      2
      3
      4
      5
      =
      a
      b
      c

      =

      1 a
      2 b
      3 c
      4
      5
      = =

Row By Row

  • Type this command in a terminal window to have the contents displayed in serial (the first through the last line of the first file followed by the first through last line of the second file):
  • paste --serial file1 file2 > combinedfile
    • Example:
    • Contents of file1 Contents of file2 Contents of combinedfile
      1
      2
      3
      4
      5
      =
      a
      b
      c

      =

      1       2       3       4       5       =
      a       b       c                         =

Top To Bottom

  • Type this command in a terminal window to have the contents displayed from top to bottom:
  • cat file1 file2 > combinedfile
    • Example:
    • Contents of file1 Contents of file2 Contents of combinedfile
      1
      2
      3
      4
      5
      =
      a
      b
      c

      =

      1
      2
      3
      4
      5
      =
      a
      b
      c

      =


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Blog at WordPress.com.