Reputation: 2249
How can i cut first word from a string, and then result store to variable?
So in the input i have String with 5 words.
Output will be 4 words without first one and must be stored in variable.
Already tried echo "First Second Third Fourth Fifth" | cut -d " " -f2-
but i can't store result in variable.
Also i don't wont to see result of executing.
Upvotes: 2
Views: 2546
Reputation: 614
What I would prefer myself, would be to have the string in a text file, and then you can do this:-
read first second third fourth fifth < file
Then you can simply use:-
echo "${first}"
etc
Read is awesome. :D
Upvotes: 0
Reputation: 785058
Use command substitution
like this:
result=$(echo "First Second Third Fourth Fifth" | cut -d " " -f2-)
echo "$result"
OR using pure BASH:
s="First Second Third Fourth Fifth"
echo "${s#* }"
OUTPUT:
Second Third Fourth Fifth
Upvotes: 4