|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Please help me in writing script
Hi ,
I have the following two files.The characters 14-18 in file input2 will match 2nd field deleimited by ~ in file input1. swadmin@tb142:/rangedoms1/working/ cat input1 P00000012~00027 P00000027~00061 P00000270~00417 P00000271~00418 P00000272~00419 P00000273~00420 P00000274~00422 P00000275~00424 P00000276~00428 P00000277~00429 P00000278~00431 P00000279~00432 P00000329~00483 P60000329~00483 P50000329~00483 P40000329~00483 P30000329~00483 P20000329~00483 P10000329~00483 P00000483~00639 P01000079~00178 P11000079~00178 P90000079~00178 P80000079~00178 P70000079~00178 P60000079~00178 P50000079~00178 P40000079~00178 P30000079~00178 P20000079~00178 P10000079~00178 P00000178~00306 swadmin@tb142:/rangedoms1/working/ cat input2 Now I want the file that contains every line in input2 but the characters 14-18 must be replaced with the matching field1 delimited by ~ in file input1 and it should not be repeated. I have used the following script which displays swadmin@tb142:/rangedoms1/working/ >awk -F'~' 'NR==FNR{a[$2]= $1;next}{print substr($0,1,13),a[substr($0,14,5)],substr($0,19)}' input1 input2 0001349000174 P00000012 0001349000174 P10000329 0001349000174 P10000079 0001349000174 P10000079 0001349000174 P10000329 0001349000174 P10000079 But P10000079, P10000329 are repeated which we don’t want. resulting file should look like the following 0001349000174 0001349000174 0001349000174 0001349000174 0001349000174 0001349000174 I have used the following script which displays swadmin@tb142:/rangedoms1/working/ >awk -F'~' 'NR==FNR{a[$2]= $1;next}{print substr($0,1,13),a[substr($0,14,5)],substr($0,19)}' input1 input2 0001349000174 P00000012 0001349000174 P10000329 0001349000174 P10000079 0001349000174 P10000079 0001349000174 P10000329 0001349000174 P10000079 But P10000079, P10000329 are repeated which we don’t want. Many thanks in advance for help being done. Regards Injam |
![]() |
| Viewing: Web Development Archives > FAQs > Unix/Linux > Please help me in writing script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|