I wrote a awk program which give me the result i needed. Finding any line beginning with 130AB : if the 2nd field contain data, move it on the 9th field
My input file :
130DD2532||1|||1|
130AB00100501||20|17112023|17112023||N|||0||
130DD2532||1|||1|
130AB00100502||20|17112023|17112023||N|||0||
130DD2532||1|||1|
130AB00100112||20|17112023|17112023||N|||0||
130DD2532||1|||1|
130AB00100113|00100113|20|17112023|17112023||N|||0||
See the last line
My program file prog.awk:
/^130AB/ { if ($2==""){print $1"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|"$10"|"$11"|"$12"|"$13"|"$14"|"$15} else { print $1"|""|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$2"|"$10"|"$11"|"$12"|"$13"|"$14"|"$15}; next; };
{ print; }
My command line :
awk -F "|" -f prog.awk myFile.txt > newFile.txt
The result : newFile.txt
130DD2532||1|||1|
130AB00100501||20|17112023|17112023||N|||0|||||
130DD2532||1|||1|
130AB00100502||20|17112023|17112023||N|||0|||||
130DD2532||1|||1|
130AB00100112||20|17112023|17112023||N|||0|||||
130DD2532||1|||1|
130AB00100113||20|17112023|17112023||N||00100113|0|||||
It work fine but does my prog.awk should'nt be more clear ? :-)
Thanks for you help
Abou Ilyès