Use space as a delimiter with cut command

前端 未结 8 1117
[愿得一人]
[愿得一人] 2020-12-07 07:24

I want to use space as a delimiter with the cut command.

What syntax can I use for this?

相关标签:
8条回答
  • 2020-12-07 08:28

    You can't do it easily with cut if the data has for example multiple spaces. I have found it useful to normalize input for easier processing. One trick is to use sed for normalization as below.

    echo -e "foor\t \t bar" | sed 's:\s\+:\t:g' | cut -f2  #bar
    
    0 讨论(0)
  • 2020-12-07 08:29

    I just discovered that you can also use "-d ":

    cut "-d "
    

    Test

    $ cat a
    hello how are you
    I am fine
    $ cut "-d " -f2 a
    how
    am
    
    0 讨论(0)
提交回复
热议问题