I'm writting an sh file where I have var as:
c=aabbcc.DP.09-25-2012_14_17.dmp
i want to copy only initial part in another var like:
d = aabbcc
How should I trim my var?
If by sh
you mean bash
, then
d="${c%%.*}"
otherwise
d="`echo "$d"|cut -d. -f1`"
will do, perhaps.
perl:
D=`echo $c | perl -lne 's/([^\.]*)\..*/\1/;print'`
sed:
D=`echo $c | sed 's/\([^\.]*\)\..*/\1/'`
awk:
D=`echo $c | awk -F. '{print $1}'`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With