Results 1 to 2 of 2

Thread: copy and paste file from one terminal to another

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Liked
    0 times
    Posts
    16

    Default copy and paste file from one terminal to another

    Hi,

    Yes, you read correct. This time around, we are going to paste data content of one text file into another text file and we are going to approach this issue using linux command via terminal. This one could be easily done inside X or GNOME, but let us assume we are going to do it from a linux system without X, say server or remote non-X linux box, something like that.

    Let's start.

    Let us view two example of text files namelyh textfile1.txt and textfile2.txt

    # cat textfile1.txt
    RedHat
    Fedora
    CentOS

    # cat textfile2.txt
    Enterprise Version
    Core Version 9
    Linux Distro


    Now, let us merge or combine two text files using the linux paste command

    # paste textfile1.txt textfile2.txt
    result:
    RedHat Enterprise Version
    Fedora Core Version 9
    CentOS Linux Distro


    Making it permanent as file would be as easy as

    # paste textfile1.txt textfile2.txt > output.txt

    Did you noticed that the contents of textfile2.txt was merged with the data contents of textfile1.txt? Noticed also the fixed columnar width making the 2nd column word vertically aligned.

    Merging two text file using paste could be very useful on specific scenarios of merging related data contents.

    Here's another scenario.

    # cat test1.txt
    Citybank
    Citybank
    BPI Bank
    Citybank

    # cat test2.txt
    New York, USA
    San Francisco, USA
    Manila, Philippines
    London, UK

    Again, using paste to merge contents of first file and second text file

    # paste test1.txt test2.txt
    result:
    Citybank New York, USA
    Citybank San Francisco, USA
    BPI Bank Manila, Philippines
    Citybank London, UK

    If you want to insert a delimeter character between two columnar data or data field, that could be done using the same linux paste command like so

    # paste -d", " test1.txt test2.txt
    result:
    Citybank,New York, USA
    Citybank,San Francisco, USA
    BPI Bank,Manila, Philippines
    Citybank,London, UK


    Neat and nice, isn't it? Hope you enjoy it, and oh, it was an old idea reminded to me by pinoyskull.

    Merging two text files with a common field or column marker would be my next post, so watch out for it. And sorry for late updates, been very busy these past few weeks.

    Related Posts:
    Merging Linux Non-Text and Binary Files
    Concatenating Multiple Linux Files
    Simple Linux Text Line Formatter
    Math the Beauty and Linux the Beast
    Retrieve MySQL data via Bash Shell

    ===============================

    To add text to the end of a file:

    $ cat footnotes.txt >> file

    If you're appending only a single line instead of multiple lines or an entire file, you can use echo instead of cat:
    $ echo "192.255.255.255 bigblue" >> /etc/hosts

    To append lines of text that are itemized beginning with 1, use cat's -n option; lines are preceded with the line number (offset with up to five space characters) and a tab character. Add the -b option to suppress the numbering of blank lines:
    $ cat -nb > file
    This line is numbered
    And so is this

    Another numbered line Ctrl-D

    $ cat file
    1 This line is numbered
    2 And so is this

    3 Another numbered line
    $

  2. #2
    Junior Member
    Join Date
    Oct 2008
    Liked
    0 times
    Posts
    4

    Default

    rocket science !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •