If I want to cut a list of text using a string as a delimiter, is that possible? For example I have a directory where a list of shell scripts call same perl script say
如果我想使用字符串作为分隔符来剪切文本列表,那可能吗?例如,我有一个目录,其中shell脚本列表调用相同的perl脚本说
abc.pl
So when I do
所以,当我这样做
$grep abc.pl *
in that directory, it gives me following results
在该目录中,它给了我以下结果
xyz.sh: abc.pl 1 2
xyz2.sh: abc.pl 2
mno.sh: abc.pl 3
pqr.sh: abc.pl 4 5
I basically want all the output after "abc.pl" (to check what range arguments are being passed to the perl right now)
我基本上想要“abc.pl”之后的所有输出(以检查现在传递给perl的范围参数)
When I tried
当我尝试
$grep abc.pl * | cut -d'abc.pl' -f2
OR
$grep abc.pl * | cut -d'abc\.pl' -f2
its giving me
它给了我
cut: invalid delimiter
When I read man for cut it states
当我读人为切,它说
delim can be a multi-byte character.
delim可以是多字节字符。
What am I doing/interpreting wrong here?
我在做什么/解释错了?
5 个解决方案
#1
When I read man for cut it states ... delim can be a multi-byte character.
当我读到man for cut时,它表示... delim可以是一个多字节字符。
Multi-byte, but just one character, not a string.
多字节,但只是一个字符,而不是字符串。
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
You can specify only output delimiter as a string (useless in this case):
您只能将输出分隔符指定为字符串(在本例中无用):
--output-delimiter=STRING
use STRING as the output delimiter the default is to use the input delimiter
#2
why not use grep abc.pl | awk '{print $3, $4}'
?
为什么不使用grep abc.pl | awk'{print $ 3,$ 4}'?
#3
Try using this.
试试这个。
$grep abc.pl * | awk -F 'abc.pl' '{print $2}'
-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预定义变量的值)。
#4
$ grep abc.pl * | cut -d' ' -f3-999
$ grep abc.pl * | cut -d'' - f3-999
In that case just use the space character as the delimiter.
在这种情况下,只需使用空格字符作为分隔符。
#5
Or you can try eg Ruby:
或者你可以尝试例如Ruby:
grep abc.pl * | ruby -ne 'p $_.chomp.split("abc.pl").last'
#1
When I read man for cut it states ... delim can be a multi-byte character.
当我读到man for cut时,它表示... delim可以是一个多字节字符。
Multi-byte, but just one character, not a string.
多字节,但只是一个字符,而不是字符串。
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
You can specify only output delimiter as a string (useless in this case):
您只能将输出分隔符指定为字符串(在本例中无用):
--output-delimiter=STRING
use STRING as the output delimiter the default is to use the input delimiter
#2
why not use grep abc.pl | awk '{print $3, $4}'
?
为什么不使用grep abc.pl | awk'{print $ 3,$ 4}'?
#3
Try using this.
试试这个。
$grep abc.pl * | awk -F 'abc.pl' '{print $2}'
-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预定义变量的值)。
#4
$ grep abc.pl * | cut -d' ' -f3-999
$ grep abc.pl * | cut -d'' - f3-999
In that case just use the space character as the delimiter.
在这种情况下,只需使用空格字符作为分隔符。
#5
Or you can try eg Ruby:
或者你可以尝试例如Ruby:
grep abc.pl * | ruby -ne 'p $_.chomp.split("abc.pl").last'