Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi everybody...
Please help me regarding this issue asap.
we have requirement ... source file contains a column contains a id (primary key) and other(2nd) column which is having one or more values like (toys,car,bus) here comma is not a filed delimeter and . Filed delimiter is a '|'. for example
Sample input:100|toys,car,bus
200|hat,soap,kite,lux
300|jugs,mugSample output should be like this:
100,toys
100,cars
100,bus
200,hat
200,soap
200,kite
200,lux
300,jugs
300,mug2nd column may contain values dynamically......
1st column is integer and 2nd column is longvarchar(2000)....
please help me regarding this....
Thanks
Prakash
I'm assuming you meant to say that after parsing the data into 2 columns by pipe symbol that the second column was then parsed by commas.
Maybe the script below will do what you want.
The only hard part is this:eval echo \"\$${i}\"
As var i changes, this evaluates and prints the contents of ${i}
Let me know if you have any questions.
#!/bin/kshi=2
while IFS="|" read col1 col2
do
# parse column 2 by commas
set - $(IFS=","; echo ${col2})
i=1
while (($i <= $#))
do
printf "%d,%s\n" $col1 $(eval echo \"\$${i}\")
((i+=1))
done
done < datafile
Report Offensive Follow Up For Removal
![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |