I have a csv file that looks like thisADRESSE_1,ADRESSE_SUITE,CODE1 boulevard Veyrier Montagnres,,331202, rue du Dbarcadre,331206 bis avenue du Gnral de Gaulle,,44180avenue du Parc Pereire,,93250On three lines, I summarize a file that contains several hundred lines.I would like to clean and then edit this file so it looks like thisNUMERO,ADRESSE_1,ADRESSE_SUITE,CODE1,boulevard Veyrier Montagnres,,331202,rue du Dbarcadre,,331206 bis,avenue du Gnral de Gaulle,,44180,avenue du Parc Pereire,,93250The lines vary from 16 to 17 columns, I can already adjust this with this script using printf to formatBEGIN {     FS = [,];     OFS = ,; }    NF != 16  {printf(%s,%s,%s,%s,%s%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n), $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17}Can someone guide me?
How to modify/organize data on a file with Awk
text processing;awk;csv
I just put my solution with sed even it's asked especially for AWK, I find this solution more compact and direct:GNU Sed (tested under CentOS): sed -n '1!p' addresses.csv | sed -r 's!^([0-9]*(\sbis|\ster)?),?(.*)$!\1,\3!g;s!(.*)([^,])(,[0-9]*)$!\1\2,\3!g'OS-X / BSD Sedsed -n '1!p' addresses.csv | sed -E 's!^([0-9]*( bis| ter)?),?(.*)$!\1,\3!g;s!(.*)([^,])(,[0-9]*)$!\1\2,\3!g'The first sed command is to take all lines except the 1st one (header). For the second sed I use substitutions: ^                : Starting text.[0-9]*           : all numbers (0, 1, ... 99, 999, 99999999 and so on) ( bis| ter)?     : optionally followed by  bis or  ter (notice the space before); group 2,?           : optionally followed by a comma(.*)$            : the rest of the string until the end ($) (group 3)!\1,\3           : replaced by first group (number + extension) - comma - third group Note the second group is the parenthesis for ' bis' and ' ter', and the first group is this ([0-9]*( bis| ter){0,1})The second substitution is to normalize the commas (if it does not finished by ,,\d we add an extra comma.