Monday, March 5, 2007
Command in discussion- "paste"
Today we will discuss about "paste". Basically it's used to merge lines of files, but it got some other uses as well. Here are they.
Normal Uses:
$ cat file1
line1 of file1
line2 of file1
line3 of file1
$ cat file2
line1 of file2
line2 of file2
line3 of file2
$ cat file3
line1 of file3
line2 of file3
line3 of file3
$ paste file1 file2 file3
line1 of file1 line1 of file2 line1 of file3
line2 of file1 line2 of file2 line2 of file3
line3 of file1 line3 of file2 line3 of file3
(-s serial)
$ paste -s file1 file2 file3
line1 of file1 line2 of file1 line3 of file1
line1 of file2 line2 of file2 line3 of file2
line1 of file3 line2 of file3 line3 of file3
(-d you can mention the delimiter)
$ paste -d : file1 file2 file3
line1 of file1:line1 of file2:line1 of file3
line2 of file1:line2 of file2:line2 of file3
line3 of file1:line3 of file2:line3 of file3
Here comes a good use of paste, formatting a output of any command with number of entries in each line as per your choice.
Suppose
$ ls
cprt.cc file1 file2 file3 main.cc newdir
Now, I want 2 file names in a line
$ ls | paste - -
cprt.cc file1
file2 file3
main.cc newdir
And three similarly
$ ls | paste - - -
cprt.cc file1 file2
file3 main.cc newdir
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment