I guess this has a simple solution but can't figure out now.
having:
x="H:a:b:c"
to get H:
echo $x|awk -F: {'print $1'}
how can I put REST of line in another one? i.e.
echo $rest
a:b:c
thanks
---------- Post updated at 08:58 PM ---------- Previous update was at 08:55 PM ----------
Well the hand icon should be a colon followed by a "b". Also lines have variable length.
danmero
2
Please use
tags next time.
x="H:a:b:c"
var1=${x%%:*}
var2=${x#*:}
$
$
$ echo "H:a:b:c" | awk '{sub(/^[^:]*:/,"",$0); print $0}'
a:b:c
$
$ echo "H:a:b:c" | awk '{print substr($0,index($0,":")+1)}'
a:b:c
$
$
tyler_durden
$ echo "$x"|sed 's/:/\n/'
H
a:b:c
or using danmero's (preferrable) sugggestion
$ echo "${x%%:*}"; echo "${x#*:}"
H
a:b:c
EAGL
5
Scrutinizer could you please explain how Danmero's suggestion works?
Hi Eagl�, danmero's suggestion uses parameter expansion