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.



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



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

Not sure I fully understand. Would this come close?

awk -F~ '!$11 {$11 = $9}1' OFS="~" file

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.