Multiple records based on ';' in the record

Hi All,

I have a *.csv files in a die /pro/lif/dow, (pipe delimiter file), these files are having 8 columns and 6 column(CDR_LOGIC) records are populated as below, I need to incorporate the below logic in all the *.csv files.

11||:ColumnA||:ColumnB
123||:ColumnA
IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF)
Decode(:ColumnA, When :columnA = '123' then :columnF,
when :Column A = '1234' then :Column T END)

I have to create a new records based on the semi colon value i.e if the cdr_logic is having more than one semi colon the entire records should be copied in the next line as below.

1Column|2Column|3Column|4Column|6Column|7Column|8Column

my input
A|B|C|D|E|11||:ColumnA||:ColumnB|G|H --- 3rd line in the file

my output should be
A|B|C|D|E|11||:ColumnA||:ColumnB|G|H -- 3rd line in the file
A|B|C|D|E|11||:ColumnA||:ColumnB|G|H -- 4th line in the file

My input example 2
A|B|C|D|E|IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF)|G|H -- 10th line in the file

my output

IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF) -- 11th line
IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF) -- 12th line
IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF) -- 13 th line
IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF) -- 14th line

For each semi colon one line should be inserted below the record.

Can any please give me an idea on how to do this.

Thx,
Shrithi

Hey,
This may not be possible in unix shell scripting , can't you handle this at source level.

As the columns are dynamic in the logic field you have to see other options in java or c.

--Mora

Hi ,

It can be possible in unix..,gurus can you please give me some basic idea on how to do this.

Thx,
Shruthi

No way we can do this in unix,you can capture the occurrences of semicolon but if you need to use as variables it can be difficult may be you can load the data in a database and write some procedural language to do this task.

--Mora

Hey try this sed script

x
s/.*//
x
s/:/;/
/:/{
: label
H
s/:/;/
t label
g
}

the output will be ; separated instead of : separated, you can replace that using another sed... or in same, but I guess this will solve the core issue.

awk -F"|" '{s=gsub(":",":",$6); for(i=1;i<=s+1;i++) print $0}' OFS="|"  input_file
# x=$(sed 's/Col/&\n/g' infile|sed -n '/Col$/=' | sed -n '$p')
for ((i = 1 ; i <= $x ; i++ )); do  pr=(${pr[@]} ";p"  ) ; done ; sed -n "$(echo ${pr[@]})" infile
A|B|C|D|E|11||:ColumnA||:ColumnB|G|H
A|B|C|D|E|11||:ColumnA||:ColumnB|G|H

run same cod after results (pr array must zero every run)

A|B|C|D|E|IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF)|G|H
A|B|C|D|E|IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF)|G|H
A|B|C|D|E|IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF)|G|H
A|B|C|D|E|IIF(:ColumnA = :ColumnC then :ColumnD else :ColumnF)|G|H

regards
ygemici