Hello All
I have data like
col1 | col2
AAA | 12,23,34
BBB | 34,32,1
My output should be like
col1 | col2
AAA | 12
AAA | 23
AAA | 34
BBB | 34
BBB | 32
BBB | 1
How can i get this working. Please reply
Hello All
I have data like
col1 | col2
AAA | 12,23,34
BBB | 34,32,1
My output should be like
col1 | col2
AAA | 12
AAA | 23
AAA | 34
BBB | 34
BBB | 32
BBB | 1
How can i get this working. Please reply
sed -e "s/|/ /" filename | while read text1 text2; do
tr "," " " $text2 | while read text3; do
echo "$text1 | $text3"
done
done
---------- Post updated at 12:32 PM ---------- Previous update was at 12:27 PM ----------
sorry there is a mistake .. try this
sed -e "s/|/ /" filename | while read text1 text2; do
for text3 in `tr "," " " $text2` ; do
echo "$text1 | $text3"
done
done
$ ruby -F"\s+\|\s+" -ane '$.>1 and ($F[-1].chomp!;$F[1]=$F[1].split(","); $F[1].each{|x| print "#{$F[0]}|#{x}\n"} )' file
AAA|12
AAA|23
AAA|34
BBB|34
BBB|32
BBB|1
awk -F \| 'NR==1{print;next}{t=split($2,a,",");for (i=1;i<=t;i++) print $1 FS a}' infile
$ ruby -F"\s+\|\s+" -ane '$.>1 and ($F[-1].chomp!;$F[1].split(",").each{|x| print "#{$F[0]}|#{x}\n"} )' file
AAA|12
AAA|23
AAA|34
BBB|34
BBB|32
BBB|1