I would like to select the column 23,24 and 27 of the 8th row.
Here is the way I have tried.
awk 'FNR == 8 {print $23,$24,$37}' file.txt
It works perfectly. However, I'm wondering how to add the corresponding file name as the $0
Then, the output should look like
file.txt colunm23 colunm24 colunm 27 <---- The 8th row.
I'm not using gawk. Please suggest based on the version before gawk 4.0.0 Thank you.
The AWK language is useful for manipulation of data files, text retrieval and processing. -F <value> - tells awk what field separator to use. In your case, -F: means that the separator is : (colon). '{print $4}' means print the fourth field (the fields being separated by : ).
awk '{ print $2; }' prints the second field of each line. This field happens to be the process ID from the ps aux output.
If you notice awk 'print $1' prints first word of each line. If you use $3, it will print 3rd word of each line.
Use the FILENAME
variable:
awk 'FNR == 8 {print FILENAME,$23,$24,$37}' file.txt
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