3 ms·
awk '{print $2,$4;}' is useful and easy to remember. $NF refers to the last field. FS is the variable to override the default field separator of white space. He
by vajrabum 8y ago
awk '{print $2,$4;}' is useful and easy to remember. $NF refers to the last field. FS is the variable to override the default field separator of white space. Here's an example of it's use. OFS is the output field separator.
awk 'BEGIN{FS=":"; OFS=":"} {print $1,$NF}' /etc/password
Works on CSV files too with the right field separator.
- masklinn 8y ago> awk '{print $2,$4;}' is useful and easy to remember. $NF refers to the last field. FS is the variable to override the default field separator of white space. Here's an example of it's use. OFS is the output field separator. Yeah also cut is just inconvenient, awk works much better when working with the usual tabulated data. > Works on CSV files too with the right field separator. You're probably better off using xsv though.
- Noumenon72 8y agoI have used awk several times in different ways. I still don't find it easy to remember a command with as many punctuation characters as letters, like your first one. And I'm not even sure what the second one is trying to do. Print the user name, followed by the number of fields separated by colons? What good is that? Perhaps you've forgotten that not everyone can read awk syntax right off the page.