Mohammedz.com

For Linux and Shell scripting.


Leave a comment

Linux commands: cut and paste

cut and paste can be handy sometimes, especially when you have to manipulate
files based on rows and columns.

simple usages of cut and paste:

file1
******
first second
first second
first second

file2
******
3 4
3 4
3 4

Let me say, I want to cut first column of file2 and paste them as last column
of file1. Here you go

# cut -d” ” -f1 file2 |paste -d” ” file1 –
first second 3
first second 3
first second 3

what if the result from cut should be pasted at the beginning of file1?

# cut -d” ” -f1 file2 |paste -d” ” – file1
3 first second
3 first second
3 first second

~mohammed

Advertisements