File parsing / Text manipulations

August 27, 2010 at 18:34:17
Specs: Windows Vista
Hello. I have a file that is | delimited. One field has multiple values in it, and I need to break that line into individual records (while repeating the common information.
So I need this:
ID-1: Simpson Family: Homer, Marge, Bart, Lisa, Maggie: Springfield

To turn into this:
ID-1: Simpson Family: Homer: Springfield
ID-1: Simpson Family: Marge: Springfield
ID-1: Simpson Family: Bart: Springfield
ID-1: Simpson Family: Lisa: Springfield
ID-1: Simpson Family: Maggie: Springfield


I haven't done scripting in a looong time. Any help is greatly appreciated!

Thanks,
mark


See More: File parsing / Text manipulations

Report •

#1
August 28, 2010 at 13:03:53
a way .....

echo "ID-1: Simpson Family: Homer, Marge, Bart, Lisa, Maggie: Springfield"|
awk ' BEGIN  { FS=":" }
{

str=$1":"$2
# split field 3 into an array
n=split($3,a,",")

for(i=1;i<=n;i++)
    print str":"a[i]":"$NF

} '


Report •
Related Solutions


Ask Question