Saturday 15 March 2014

regex - reorder great number of columns in a text file -


I need a method (awk / perl / sed / shell) to modify the contents of a file below:

ago:

  123456 | ABCDEF | 123 | 011 | A. E Neil | R | Unconnection | A1 A2 B1 | B2 | C1 | C2 || 2013 | 2013 | 9999 | After Y   

:

  123456 | ABCDF | 123 | 011 | A. E Neil | R | Unknown | 9999 | Y A1 After the 9th column I need to move the last 2 columns, remove the columns 11, 13, 15 and enter the code between <14th and 15th column ( c1 | 2013 )> Null | NULL | NULL  Any suggestions appreciated can not change the command of the  Cut  command, so there will be need to go in any other way. There are 10 million such lines in the input file and I'm looking for the best way to do this.   

The ugly question asks for an ugly solution:

  awk - F "|" '{For (i = 1; i & lt; = 9; i ++) {printf "% s |" , $ I} printf "% s |% s |", $ (NF-1), $ NF (i = 10; i <16; i + = 2) {printf "% s |" , $ I} printf "% s |% s |% s |", "NULL", "NULL", "NULL" for (i = 16; i <(NF -2); i ++) { Printf "% s |", $ I} print $ (NF-2)} 'inputfile'    

No comments:

Post a Comment