Read and write operations on files.

Dears.
kindly guide !!!

I have data, which is delimited by | .
it should contain 26 columns, but one column data contain | makes few row to 27 columns.

I want to find rows have 27 columns and then concatenate the specific columns to single column to make it 26 columns.

Kindly help, Can it be done ?

 awk -F '|' '{print NF}' COMPLAINT_EVENT_TWO.processing | sort | uniq -c

 78 26
  3 27

Suppose column 19,and 20 need to concatenate to make it single column(19).
How can i achieve it?

Regards,
Sadique

awk 'NF==27 {$19=$19 $20; $20="=-="; sub("\\|" $19 "\\|=-=\\|", "|" $19 "|")} {print $0}' FS="|" OFS="|" COMPLAINT_EVENT_TWO.processing
1 Like

Thanks rdrtx1, it worked perfectly for me.

You could also try:

awk 'NF==27 {$19=$19 $20; for(i=20;i<NF;i++) $i=$(i+1);NF--}1' FS='|' OFS='|'  COMPLAINT_EVENT_TWO.processing

Which avoids using the dummy =-= string.

1 Like