如何告诉awk使用=作为分隔符(同时删除空格)
假设我有以下文件如何告诉awk使用=作为分隔符(同时删除空格),awk,Awk,假设我有以下文件 John=good Tom = ok Tim = excellent 我知道以下内容,让我们使用=作为分隔符 awk -F= '{print $1,$2}' file 这给了我以下结果 John good Tom ok Tim excellent 我希望空白被忽略,这样只有名字和他们的表演被打印出来 解决这个问题的一种方法是对结果运行另一个awk awk -F= '{print$1,$2}' file | awk '{print $1,$2}'
John=good
Tom = ok
Tim = excellent
我知道以下内容,让我们使用=
作为分隔符
awk -F= '{print $1,$2}' file
这给了我以下结果
John good
Tom ok
Tim excellent
我希望空白被忽略,这样只有名字和他们的表演被打印出来
解决这个问题的一种方法是对结果运行另一个awk
awk -F= '{print$1,$2}' file | awk '{print $1,$2}'
但是我想知道我是否可以在一个
awk
?中将它们包含在分隔符定义中;这是一个regexp
jinx:1654 Z$ awk -F' *= *' '{print $1, $2}' foo.ds
John good
Tom ok
Tim excellent
将其包含在分隔符定义中;这是一个regexp
jinx:1654 Z$ awk -F' *= *' '{print $1, $2}' foo.ds
John good
Tom ok
Tim excellent
FS变量可以设置为正则表达式 来自AWK手册
The following table summarizes how fields are split, based on the value of FS.
FS == " "
Fields are separated by runs of whitespace. Leading and trailing whitespace are ignored. This is the default.
FS == any single character
Fields are separated by each occurrence of the character. Multiple successive occurrences delimit empty fields, as do leading and trailing occurrences.
FS == regexp
Fields are separated by occurrences of characters that match regexp. Leading and trailing matches of regexp delimit empty fields.
FS变量可以设置为正则表达式 来自AWK手册
The following table summarizes how fields are split, based on the value of FS.
FS == " "
Fields are separated by runs of whitespace. Leading and trailing whitespace are ignored. This is the default.
FS == any single character
Fields are separated by each occurrence of the character. Multiple successive occurrences delimit empty fields, as do leading and trailing occurrences.
FS == regexp
Fields are separated by occurrences of characters that match regexp. Leading and trailing matches of regexp delimit empty fields.