Imagine. both ways actually work, but I think this is correct.
]$ sed s'/[0-9]*\.[0-9]*$/\$&/' receipt
5390:Captain Crunch:$4.59
2460:Milk:$2.99
8735:Peanut Butter:$3.39
4402:Yogurt:$0.99
Duh!
I agree with sycamorex. Think abut it a few minutes and you can get it down to one line.
[$] sed s'/[0-9]*.[0-9]*$/\$&/' receipt
5390:Captain Crunch:$4.59
2460:Milk:$2.99
8735:Peanut Butter:$3.39
4402:Yogurt:$0.99
================
This is too long but it might be useful for something else.
cat file |
while read line
do
array=(`echo $line | sed s'/ //g' | sed s'/:/ /g'`)
echo "${array[0]}:${array[1]}:\$${array[2]}"
done
[tmp]# ./ex
5390:CaptainCrunch:$4.59
2460:Milk:$2.99
8735:PeanutButter:$3.39
4402:Yogurt:$0.99
Quote:
Originally Posted by ibuc
I took a liberty with your data file and got rid of some spaces. I was in a bash shell. <file> is your data file.
cat file |
while read line
do
array0=(`echo $line|sed s'/ //g'`)
array=(`echo $array0|sed s'/:/ /g'`)
echo "${array[0]}:${array[1]}:\$${array[2]}"
done
[tmp]# ./ex
5390:CaptainCrunch:$4.59
2460:Milk:$2.99
8735:PeanutButter:$3.39
4402:Yogurt:$0.99
|