I have a requirement to select the 7th column from a tab delimited file. eg:
cat filename | awk '{print $7}'
The issue is that the data in the 4th column has multiple values with blank in between. example - The last line in the below output:
user \Adminis FL_vol Design 0 - 1 - group 0 FL_vol Design 19324481 - 3014 - user \MAK FL_vol Design 16875161 - 2618 - tree 826 FL_vol Out Global Doc Mark 16875162 - 9618 - /vol/FL_vol/Out Global Doc Mark
You can cut in awk using awk's function split . You can also filter records using a regex condition within awk, making grep and cut superfluous. This breaks down like: Set the output field separator to be a pipe between two spaces.
in Perl. If you have an existing awk program, and wish it to run with Perl, you can perform a mechanical translation using the a2p utility provided with the Perl distribution. This utility converts the awk syntax into the Perl syntax, and for the vast majority of awk programs, provides a directly runnable Perl script.
awk is more powerfull than cut. if you need to use tail or head or sort or similars, and cut, you can make one single awk for that. Like other posters said, if you can use cut for you problem you should choose it instead of awk, but there are situations where cut just isn't enough.
If the data is unambiguously tab-separated, then cut
will cut on tabs, not spaces:
cut -f7 filename
You can certainly do that with awk
, too:
awk -F'\t' '{ print $7 }'
If fields are separated by tabs and your concern is that some fields contain spaces, there is no problem here, just:
cut -f 7
(cut defaults to tab delimited fields.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With