Explain awk

Hi,

I found this command in this forum, but, couldnt understand much from it.

could any one help me understand that???

the commands are :

awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2
awk '{sub(/~ */,x);printf $0(/\|$/?ORS:x)}'
awk '{sub(/~ */,x);sub(/\|$/, "|\n")}8' ORS="" file1 >file2

the purpose is to remove all "~" characters and fix the broken lines

existing file data:

24|john|account ~ info |56|
25|kuo|account ~ journal |58|
27|kim|account ~ journal |59|
28|San|account ~ 
journal |60|
29|jay|account ~ journal |26|
29|Nan|account ~ 
journal |66|
30|Kee|account ~ journal |27|

Output: 

24|john|account info |56|
25|kuo|account journal |58|
27|kim|account journal |59|
28|San|account journal |60|
29|jay|account journal |26|
29|Nan|account journal |66|
30|Kee|account journal |27|

I am not able to understand the last part of the command where ORS(output record separator) is used

awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2

For each input line :

sub(/ ~/,"");
Remove'~' and all following spaces (replaced by empty sting "").

($0~/\|$/?ORS:"")
If the input line ends with '|' then the value of the expression ORS, else the value is an empty string.
ORS is a variable that contains the Output Record Separator that is used par awk when printing data to stdout (with print statement); The default value of ORS is '\n'.

printf $0 ($0~/\|$/?ORS:"")
Displays the input line, followed by a new line (ORS) if ending with '|'.

The 3 commands are varitions a the same technique.

jean-Pierre.

Thanks jean-Pierre, are you from grenoble by an chance???

Pas de chance, plus � l'ouest : Bordeaux.

Jean-Pierre.

I asked you because one of the developers of my application was called by your name and is from grenoble. anyways, looks like you have a vast knowledge of unix scripting. do you mind, telling me where do you refer????