Reputation: 107
I have this..
$input = "echo a b c d"
echo -e "$input" | cut -d " " -f 2-
but I just want a simple cut that will get rid of echo as well as print
a b c d #(single space) only
Upvotes: 2
Views: 10232
Reputation: 46826
You don't need any tools besides what bash provides built-in.
[ghoti@pc ~]$ input="echo a b c d"
[ghoti@pc ~]$ output=${input// / }
[ghoti@pc ~]$ echo $output
echo a b c d
[ghoti@pc ~]$ echo ${output#* }
a b c d
[ghoti@pc ~]$
Up-side: you avoid the extra overhead of pipes.
Down-side: you need to assign an extra variable, because you can't do complex pattern expansion within complex pattern expansion (i.e. echo ${${input// / }#* }
won't work).
Upvotes: 4
Reputation: 97938
With sed:
sed -e 's/[ ]*[^ ]*[ ]*\(.*\)/\1/' -e 's/[ ]*/ /g' -e 's/^ *//' input_file
Upvotes: 1
Reputation: 530990
A little roundabout, but interesting:
( set -- $input; shift; echo $@ )
Upvotes: 3
Reputation: 1837
echo -e "$input" | tr -s ' ' | cut -d " " -f2-
Also gets rid of the 'echo'.
Upvotes: 5