Tuesday, December 6, 2011

Grep & Cut

cat -n file.txt
     1 a11,a12,a13,a14
     2 a21,a22,a23,a24
     3 a31,a32,a22,a34
     4 a41,a42,a43,a44

ubuntu1004@ubuntu1004:~$ grep a22 file.txt
a21,a22,a23,a24
a31,a32,a22,a34
ubuntu1004@ubuntu1004:~$ grep -rn a22 file.txt
2:a21,a22,a23,a24
3:a31,a32,a22,a34
ubuntu1004@ubuntu1004:~$ grep a22 file.txt | cut -d\, -f1
a21
a31
ubuntu1004@ubuntu1004:~$ grep a22 file.txt | cut -d\, -f1,3
a21,a23
a31,a22

No comments:

Post a Comment