分隔符分隔字符串
Is is possible to cut
in Linux using a string as the delimiter?
cut --delimiter="delim" -f 1,3
cut
reports:
cut
报告:
cut: the delimiter must be a single character
The most closest solution that I find is using awk
/gawk
:
我找到的最接近的解决方案是使用awk
/ gawk
:
awk -F 'delim' '{print $1; print $3}'
From the manual:
从手册 :
-F fs
–field-separator fs Use fs for the input field separator (the value of the FS predefined variable).-F fs
–field-separator fs将fs用作输入字段分隔符(FS预定义变量的值)。
An you can also use regular expression for the delimiter (field separator):
您还可以将正则表达式用作分隔符(字段分隔符):
Similarly, if the FPAT variable is set to a string representing a
regular expression, each field is made up of text that matches that
regular expression. In this case, the regular expression describes the
fields themselves, instead of the text that separates the fields.
Assigning a new value to FS or FIELDWIDTHS overrides the use of FPAT.同样,如果FPAT变量设置为表示
正则表达式,每个字段均由与其匹配的文本组成
正则表达式。 在这种情况下,正则表达式描述了
字段本身,而不是用文本分隔字段。
为FS或FIELDWIDTHS分配新值将覆盖FPAT的使用。
翻译自: https://www.systutorials.com/cut-using-a-string-as-the-delimiter/
分隔符分隔字符串