Is it possible to use a string as a delimiter in unix cut command?

后端 未结 5 542
长发绾君心
长发绾君心 2021-02-07 04:18

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

相关标签:
5条回答
  • 2021-02-07 04:32

    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).

    0 讨论(0)
  • 2021-02-07 04:41

    why not use grep abc.pl | awk '{print $3, $4}'?

    0 讨论(0)
  • 2021-02-07 04:44

    Or you can try eg Ruby:

    grep abc.pl * | ruby -ne 'p $_.chomp.split("abc.pl").last'
    
    0 讨论(0)
  • 2021-02-07 04:47

    When I read man for cut it states ... delim can be a multi-byte character.

    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
    
    0 讨论(0)
  • 2021-02-07 04:50

    $ grep abc.pl * | cut -d' ' -f3-999

    In that case just use the space character as the delimiter.

    0 讨论(0)
提交回复
热议问题