Alexander Mills
Alexander Mills

Reputation: 100190

How to keep everything but the first token with bash pipe?

Say I have this:

echo "   word1  word2 word3" | awk '{print $1;}' # Prints "word1"

I want to remove everything before the beginning of the second token, so I want to keep word2 word3..what I could do is just remove the first token and then trim the remainder, but I don't know how to keep everything but the first token.

Upvotes: 0

Views: 216

Answers (2)

user1934428
user1934428

Reputation: 22291

  echo "   word1  word2      word3" | read skip rest

Will store just word2 word3 on rest. See the read command in the bash man page.

Upvotes: 1

Erez Ben Harush
Erez Ben Harush

Reputation: 867

awk has for: echo " word1 word2 word3" | awk '{for(i=2;i<=NF;++i)print $i}'

Upvotes: 0

Related Questions