I've a series of words in the format "abc0001d" till "abc1999d".
I would like to use delimiter to cut the word from abc0001s to two words:
abc00 and 01d. Help me in finding the correct delimiter to cut in desired way.
I've a series of words in the format "abc0001d" till "abc1999d".
I would like to use delimiter to cut the word from abc0001s to two words:
abc00 and 01d. Help me in finding the correct delimiter to cut in desired way.
$ echo "abc0001d" | awk '{print substr($0,1,5)}'
abc00
$ echo "abc0001d" | awk '{print substr $0,6,3)}'
01d
With a space as delimiter:
echo "abc0001d" | sed 's/\(.....\)\(.*\)/\1 \2/'
You can use cut character option to get the result
while read line
do
firstFour=`echo $line|cut -c1-5`
lastThree=`echo $line|cut -c6-8`
echo "First Four= $firstFour"
echo "Last Three= $lastThree"
done < file
$ x=abc0001d
$ first=${x:0:5}
$ echo $first
abc00
$ second=${x:5:7}
$ echo $second
01d
Another way,
$ a=abc0001d
$ echo ${a:0:5}
abc00
$ echo ${a:5}
01d
EDIT : Simultaneous posting. Same solution as above.
Thanks for your help
echo abc0001d | sed -e "s/...$/ &/g"
abc00 01d