是否可以在unix cut命令中使用字符串作为分隔符?

Dev*_*dar 17 unix utilities cut

如果我想使用字符串作为分隔符来剪切文本列表,那可能吗?例如,我有一个目录,其中shell脚本列表调用相同的perl脚本说

abc.pl
Run Code Online (Sandbox Code Playgroud)

所以,当我这样做

$grep abc.pl * 
Run Code Online (Sandbox Code Playgroud)

在该目录中,它给了我以下结果

xyz.sh: abc.pl 1 2
xyz2.sh: abc.pl 2
mno.sh: abc.pl 3
pqr.sh: abc.pl 4 5
Run Code Online (Sandbox Code Playgroud)

我基本上想要"abc.pl"之后的所有输出(以检查现在传递给perl的范围参数)

当我尝试

$grep abc.pl * | cut -d'abc.pl' -f2
Run Code Online (Sandbox Code Playgroud)

要么

$grep abc.pl * | cut -d'abc\.pl' -f2
Run Code Online (Sandbox Code Playgroud)

它给了我

cut: invalid delimiter
Run Code Online (Sandbox Code Playgroud)

当我读人为切,它说

delim可以是多字节字符.

我在做什么/解释错了?

小智 10

试试这个.

$grep abc.pl * | awk -F 'abc.pl' '{print $2}'
Run Code Online (Sandbox Code Playgroud)

-F fs --field-separator fs将fs用于输入字段分隔符(FS预定义变量的值).


ale*_*asi 8

当我阅读man for cut时,它表示... delim可以是一个多字节字符.

多字节,但只是一个字符,而不是字符串.

canti:~$ ll | cut --delimiter="delim" -f 1,2
cut: the delimiter must be a single character
Try `cut --help' for more information.

canti:~$ cut --version  
cut (GNU coreutils) 5.97
Run Code Online (Sandbox Code Playgroud)

您只能将输出分隔符指定为字符串(在本例中无用):

 --output-delimiter=STRING                                                          
        use STRING as the output delimiter the default is to use the input delimiter
Run Code Online (Sandbox Code Playgroud)


ala*_*mar 7

为什么不用grep abc.pl | awk '{print $3, $4}'