0

I want to read 9th column of text file with '~' delimiter and need to retrieve data from for the corresponding 11th column which resides in a table. that data i need to replace in 11th column of the file which is having NULL values currently.

How to achieve this in unix.

col1~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13

data1~data2~data3~data4~data5~data6~data7~data8~data9~data10~~data12~data13

in the data data11 is null . so i want to take the corresponding value for data9 and replace the data11.

Thanks

1

If you want only to copy column 9 to column 11 this can be done with script like this:

awk 'BEGIN {FS="~"; OFS="~"}{$11=$9; print}' <filename>

If the first file have only one line you can do something like:

awk -v val=$(awk -F\~ '{print $9}' <filename b>) 'BEGIN {FS="~"; OFS="~"}{$11=val; print}' <filename a>
  • otherwise if i want to replace the data from col2 in b file to col11 in a file. how can i achieve this. – Lakshminarayana Reddy Nov 13 '18 at 13:52
  • @LakshminarayanaReddy, please clarify this explicitly in question. Its very unclear. I will add something which you can use but w/o precise question this may or may not work. Is it file a only one line or you want to to replace from multiline file? – Romeo Ninov Nov 13 '18 at 13:55
1

Not sure I fully understand. Would this come close?

awk -F~ '!$11 {$11 = $9}1' OFS="~" file
col1~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13
data1~data2~data3~data4~data5~data6~data7~data8~data9~data10~data9~data12~data13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.