Home > php教程 > PHP开发 > Linux: Use the awk command to get a certain line or column of text

Linux: Use the awk command to get a certain line or column of text

高洛峰
Release: 2016-12-15 11:44:56
Original
2577 people have browsed it

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

2) nlines=$(awk 'END{print NR}' filename)


More Linux: Use the awk command to get a certain line or column of text. For related articles, please pay attention to PHP Chinese website!


🎜
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template