Thursday, April 23, 2009

Merge lines using paste utility on linux

In the post Retrieve column from file using cut utility in linux written on http://arjudba.blogspot.com/2009/04/retrieve-column-from-file-using-cut.html
it is discussed about the cut utility. The same example is used in this post. The paste command is used to merge lines together. For example in the cut example I made two files named id.txt and grade.txt. In this example I will merge them into one using paste utility.

The syntax of using paste utility is,

paste {file1} {file2}

The first line of file2 is appended to the first line of file1.
The second line of file2 is appended to the second line of file1 and so on.

Now we will make a file named id_grade.txt that will merge two files named id.txt and grade.txt generated in http://arjudba.blogspot.com/2009/04/retrieve-column-from-file-using-cut.html

To do so issue,
# paste id.txt grade.txt > id_grade.txt

Let's see the information inside id_grade.txt

# cat id_grade.txt
024401 4.98
022401 3.98
021401 4.76
024402 4.02
022402 3.99

Related Documents
http://arjudba.blogspot.com/2009/04/retrieve-column-from-file-using-cut.html

No comments:

Post a Comment