Scripting to fix the issue in UNIX file having delimiter "|"

hello All,

I am new user to shell scripting, kindly advise on the below?

I have a file where i have gaps & the delimiter falls in next line and new line is also created , plz see the example :employee.txt

Now the issue here is , i wan to write a script , where i can use "|" to get the contents in line , plz let me know if this is possible to write script as per all the line should not fall to the next line:wall:

 
cat employee.txt 
2344| walter|richey lenord| engineer | 4567
2341| terry|richey lenord
 
|engineer | 4567
2344| salter|leopord cafe | treasure | 4988
2144| jacob 
|kistern manufac| hitlor | 4563
2644| walter|richey lenord | engineer 
| 4167
2804| walter
|richey lenord | engineer | 4767

Regards,
Sunny

while IFS="|" read A B C D E F G
do
...
done < inputfile

The code did not work say's command not found on line 3

Regards,
Sunny

You don't put ... literally.

You replace it with whatever you want.

I don't understand what you mean by 'fall to the next line' however.

when i receive the file through another system the line should read as :

Where you have the text "|enon engineer | 4567" pushed up on the previous line , like the correct order.

 
Correct order :
2344| walter|richey lenord| engineer | 4567
 
 
Incorrect order :
2341| terry|richey lenord
 
|engineer | 4567
 
2344| salter|leopord cafe | treasure | 4988
2144| jacob

Run this program to fix your file:

awk '/\|/' employee.txt | sed '/[^0-9]$/{h;N;s/\n//;}'

and read using script provided by Corona688

To repair try:

awk -F\| '{while(NF<5||$NF==""){getline p; $0=$0 p}}1' file