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:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: