How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All,
I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted...

AA ATIU2345098809 009697 005374
BB ATIU2345097809 005445 006518
CC ATIU9685098809 003215 003571
DD ATIU9685098709 006878 002344
EE ATIU2315098809 005649 005377
FF ATIU2315098809 005231 005354
TT TTT TTT

I want to convert this file into a pipe delimited file as shown below without including the last row in the above file(ie TT TTT TTT),

2345|98|809||x|969|0
2345|97|809||x|544|0
2345|98|809||y|0|537
2345|97|809||y|0|651
9685|98|809||x|321|0
9685|98|809||x|687|0
9685|98|709||y|0|357
9685|98|709||y|0|234
2315|98|809||x|564|0
2315|98|809||x|523|0
2315|98|809||y|0|537
2315|98|809||y|0|535

Sorry. I seem to have messed up your post.

This is what it looks like raw:

It's a nightmare! Now I gotta try to fix it!

I'm sorry if u r confused with the post.:confused::o.... I have changed the colour so that you could understand my requirement.

Is that color is essential?? because we cant able to understand your requirement??

Hi, see if this works:

sed '$d;s/.......\(....\).\(..\)\(...\)...\(...\)....\(...\).*/\1|\2|\3||x|\4|0\n\1|\2|\3||y|0|\5/' infile
2345|98|809||x|969|0
2345|98|809||y|0|537
2345|97|809||x|544|0
2345|97|809||y|0|651
9685|98|809||x|321|0
9685|98|809||y|0|357
9685|98|709||x|687|0
9685|98|709||y|0|234
2315|98|809||x|564|0
2315|98|809||y|0|537
2315|98|809||x|523|0
2315|98|809||y|0|535
1 Like

This has nothing to do with color. I changd the colour so that u guys could understand it beter. Do you want me to re-post this without the colors?

There's no need to resubmit your post. But you also don't need so many, especially bright, colours - red-blue-red-blue-red would work for me!

Now, if you had used code tags, I wouldn't have had to edit you post in the first place :wink:

1 Like

Hey,I did'nt knew about it..this is a great feature..:slight_smile: Thanks for the help..:slight_smile: