Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the first word in a text stream

Tags:

bash

sed

awk

cat

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

For example,

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

I want:

$ cat myfile | magiccommand text 1 text 2 text 3 

How would I go about this using Bash? I could use awk '{print $2 $3 $4 $5 ....}', but that's messy and would result in extra spaces for all null arguments. I was thinking that sed might be able to do this, but I could not find any examples of this.

like image 480
Trcx Avatar asked Oct 18 '11 21:10

Trcx


People also ask

How do I remove the first part of a string in bash?

Using the parameter expansion syntax To remove the first and last character of a string, we can use the parameter expansion syntax ${str:1:-1} in the bash shell.

How do I remove a word from grep?

How to Exclude a Single Word with grep. The most simple way to exclude lines with a string or syntax match is by using grep and the -v flag. The output will be the example. txt text file but excluding any line that contains a string match with “ThisWord”.

How do I cut a word in Linux?

-c (column): To cut by character use the -c option. This can be a list of numbers separated comma or a range of numbers separated by hyphen(-). Tabs and backspaces are treated as a character. It is necessary to specify list of character numbers otherwise it gives error with this option.


1 Answers

Based on your example text,

cut -d' ' -f2- yourFile 

should do the job.

like image 88
Kent Avatar answered Sep 20 '22 17:09

Kent