linux awk -F
时间: 2023-12-02 08:36:06 浏览: 89
Linux AWK 命令
The "-F" option in the awk command is used to specify the field separator. This option tells awk to split input lines into fields using the specified delimiter. For example, if we have a comma-separated file, we can use "-F," to tell awk to treat commas as the field separator.
Syntax:
awk -F<delimiter> '{<action>}' <filename>
Example:
Consider the following file "employees.txt" which contains information about employees in a company:
John,Doe,35,Male,Manager
Jane,Smith,28,Female,Engineer
Mark,Johnson,42,Male,Developer
Emily,Davis,23,Female,Intern
To print the first name of each employee, we can use the following command:
awk -F, '{print $1}' employees.txt
Output:
John
Jane
Mark
Emily
In this example, we used "-F," to specify that the fields in our input file are separated by commas. The "{print $1}" action tells awk to print the first field of each line.
阅读全文