Remove First Word in text stream

前端 未结 5 1655
情深已故
情深已故 2020-12-29 03:04

How would I remove the first word from each line of text in a stream? i.e.

$cat myfile 
some text 1
some text 2
some text 3

what I want i

相关标签:
5条回答
  • 2020-12-29 03:24

    Here is a solution using awk

    awk '{$1= ""; print $0}' yourfile 
    
    0 讨论(0)
  • 2020-12-29 03:25

    To remove the first word, until space no matter how many spaces exist, use: sed 's/[^ ]* *//'

    Example:

    $ cat myfile 
    some text 1
    some  text 2
    some     text 3
    
    $ cat myfile | sed 's/[^ ]* *//'
    text 1
    text 2
    text 3
    
    0 讨论(0)
  • 2020-12-29 03:32

    run this sed "s/^some\s//g" myfile you even don't need to use a pipe

    0 讨论(0)
  • 2020-12-29 03:34

    based on your example text,

    cut -d' ' -f2- yourFile
    

    should do the job.

    0 讨论(0)
  • 2020-12-29 03:41

    That should work:

    $ cat test.txt
    some text 1
    some text 2
    some text 3
    
    $ sed -e 's/^\w*\ *//' test.txt
    text 1
    text 2
    text 3
    
    0 讨论(0)
提交回复
热议问题