paste
paste is an excellent command for text processing, even though its uses are limited. It can mainly be used to append the contents of files. paste is helpful in creating text files by combining
individual files such that all the lines appear on the same row in the destination file i:e linearly.
Example 1)
You have two files as shown.
/users/higgs$ cat Start_Times.log
Getname( ) at Fri Dec 30 22:29:16 IST 2011
Getip( ) at Fri Dec 30 22:30:22 IST 2011
Checkip( ) at Fri Dec 30 22:30:23 IST 2011
Getfile( ) at Fri Dec 30 22:31:22 IST 2011
/users/higgs$ cat End_Times.log
Getname( ) at Fri Dec 30 22:29:17 IST 2011
Getip( ) at Fri Dec 30 22:30:28 IST 2011
Checkip( ) at Fri Dec 30 22:30:24 IST 2011
Getfile( ) at Fri Dec 30 22:31:42IST 2011
If you have to combine these files such that the start and end times of a function appear on a common line, use paste as follows.
/users/higgs$paste Start_Times.log End_Times.log
Getname( ) at Fri Dec 30 22:29:16 IST 2011 Getname( ) at Fri Dec 30 22:29:17 IST 2011
Getip( ) at Fri Dec 30 22:30:22 IST 2011 Getip( ) at Fri Dec 30 22:30:28 IST 2011
Checkip( ) at Fri Dec 30 22:30:23 IST 2011 Checkip( ) at Fri Dec 30 22:30:24 IST 2011
Getfile( ) at Fri Dec 30 22:31:22 IST 2011 Getfile( ) at Fri Dec 30 22:31:42IST 2011
Notice that one space was added in between the two same rows of the two files .This
is default for paste without any option.
In some cases you may need to place a different delimiter between lines of the row.
/users/higgs$ paste -d ‘,’ Start_Times.log End_Times.log >Start_end_times.csv.
/users/higgs$ cat Start_end_times.csv
Getname( ) at Fri Dec 30 22:29:16 IST 2011, Getname( ) at Fri Dec 30 22:29:17 IST 2011
Getip( ) at Fri Dec 30 22:30:22 IST 2011 , Getip( ) at Fri Dec 30 22:30:28 IST 2011
Checkip( ) at Fri Dec 30 22:30:23 IST 2011 , Checkip( ) at Fri Dec 30 22:30:24 IST 2011
Getfile( ) at Fri Dec 30 22:31:22 IST 2011 ,Getfile( ) at Fri Dec 30 22:31:42IST 2011
Open this file Start_end_times.csv in windows excel if you want a better view.
Example 2)
If you want the contents to appear serially,use paste –s.
Imagine you have two files
/users/higgs$ cat Booked.log
Don2
Sherlock_homes
Mission_Impossible4
The_Dirty_picture
/users/higgs$cat Showtime.log
10:30
14:20 4 spaces after each line
17:40
22:45
/users/higgs$paste -s Booked.log Showtime.log
Don2 Sherlock_homes Mission_Impossible4 The_Dirty_picture
10:30 14:20 17:40 22:45
No comments:
Post a Comment