Delimiters missing

Hi
I have a pipe-delimited file where I eventually need to replace a string stored on the 3th field on a specific record.

This is how the file looks like:

A|Mike|Lvl 1|...
B|...
A|Maria|Lvl 1|...
C|...
B|...
A|Jimmy|Lvl 2|...
C|...
A|Carry|Lvl 0|...
C|...
B|...
A|John|Lvl 8|...
C|...

I want to change "Lvl 1" and "Lvl 2" to "Lvl 3".

A|Mike|Lvl 3|...
B|...
A|Maria|Lvl 3|...
C|...
B|...
A|Jimmy|Lvl 3|...
C|...
A|Carry|Lvl 0|...
C|...
B|...
A|John|Lvl 8|...
C|...

I.e. I need to check if it�s a "A" record, and if the third field states "Lvl 1" or "Lvl 2".

awk 'BEGIN {FS="|"}{if ($1 == "A") {if ($3 == "Lvl 0" || $3 == "Lvl 1") $3="Lvl 3"};print $0}' input_file > output_file

This works (not pretty though) but it screws up my pipe delimiters. Any suggestion? Many thanks.

you need to change the output field seperator which is space by default to ' | '

awk 'BEGIN {OFS="|"; FS="|"}{if ($1 == "A") {if ($3 == "Lvl 0" || $3 == "Lvl 1") $3="Lvl 3"};print $0}'  file

Great, thanks!