EX;
cut -d ' ' -f 2-7retrieves the second to seventh field assuming that each field is separated by a single (note: single) blank. Fields are counted starting from one.
Here is example on how to print first and the second from the last columns:perl -naF 'next if /^#/; print "$F[3]\n"'
perl -lane 'print "$F[0]:$F[-2]\n"'Here's a more complex one-line script that will print out the fourth word of every line, but also skip any line beginning with a # because it's a comment line.
cut -c 4,5,20 foo # cuts foo at columns 4, 5, and 20.cut -c -5 a.dat | more # same as above but using open range
cut -c 1-5 a.dat | more # print the first 5 characters of every line in the file a.dat
cut -d ":" -f1,7 /etc/passwd # cuts fields 1 and 7 from /etc/passwd
cut -d ":" -f 1,6- /etc/passwd # cuts fields 1, 6 to the end from /etc/passwd
No comments:
Post a Comment