1. Print the first column (field) of the file: awk '{print $1}' filename
2. Print the first two columns (field) of the file: awk '{print $1,$2}' filename
3. Print the first two columns (field) of the file: awk '{print $1,$2}' filename
3. One column, and then print the second column: awk '{print $1 $2}' filename
4. Print the total number of lines of the text file: awk 'END{print NR}' filename
5. Print the first line of text: awk 'NR= =1{print}' filename
6. Print the second line and first column of the text: sed -n "2, 1p" filename | awk 'print $1'
There are two assignment methods in the shell, the format is
1) arg=`(command)`
2) arg=$(command)
Therefore, if you want to assign the total number of lines of a certain file to the variable nlines, it can be expressed as:
1) nlines=`(awk 'END{print NR}' filename)`
or