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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert a space delimited file into a pipe delimited file using shellscript?
# 1  
Old 09-25-2011
Question 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...
Code:
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),
Code:
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


Last edited by Scott; 09-25-2011 at 05:31 AM.. Reason: Added code tags; nithins007 - please, if you must use colour, use ones that are more easily readable
# 2  
Old 09-25-2011
Sorry. I seem to have messed up your post.

This is what it looks like raw:
Quote:

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 ATIU[COLOR="Red"]2345[/COLOR]0[COLOR="rgb(255, 0, 255)"]98[/COLOR][COLOR="Lime"]809[/COLOR] 00[COLOR="Cyan"]969[/COLOR]7 00[COLOR="Yellow"]537[/COLOR]4
BB ATIU[COLOR="red"]2345[/COLOR]0[COLOR="rgb(255, 0, 255)"]97[/COLOR][COLOR="lime"]809[/COLOR] 00[COLOR="Cyan"]544[/COLOR]5 00[COLOR="yellow"]651[/COLOR]8
CC ATIU[COLOR="red"]9685[/COLOR]0[COLOR="rgb(255, 0, 255)"]98[/COLOR][COLOR="lime"]809[/COLOR] 00[COLOR="rgb(0, 255, 255)"]321[/COLOR]5 00[COLOR="yellow"]357[/COLOR]1
DD ATIU[COLOR="red"]9685[/COLOR]0[COLOR="rgb(255, 0, 255)"]98[/COLOR][COLOR="lime"]709[/COLOR] 00[COLOR="rgb(0, 255, 255)"]687[/COLOR]8 00[COLOR="yellow"]234[/COLOR]4
EE ATIU[COLOR="red"]2315[/COLOR]0[COLOR="rgb(255, 0, 255)"]98[/COLOR][COLOR="lime"]809[/COLOR] 00[COLOR="rgb(0, 255, 255)"]564[/COLOR]9 00[COLOR="yellow"]537[/COLOR]7
FF ATIU[COLOR="red"]2315[/COLOR]0[COLOR="rgb(255, 0, 255)"]98[/COLOR][COLOR="lime"]809[/COLOR] 00[COLOR="rgb(0, 255, 255)"]523[/COLOR]1 00[COLOR="yellow"]535[/COLOR]4
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),
[COLOR="Red"]2345[/COLOR]|[COLOR="Magenta"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||x|[COLOR="Cyan"]969[/COLOR]|0
[COLOR="red"]2345[/COLOR]|[COLOR="rgb(255, 0, 255)"]97[/COLOR]|[COLOR="lime"]809[/COLOR]||x|[COLOR="rgb(0, 255, 255)"]544[/COLOR]|0
[COLOR="red"]2345[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||y|0|[COLOR="yellow"]537[/COLOR]
[COLOR="red"]2345[/COLOR]|[COLOR="rgb(255, 0, 255)"]97[/COLOR]|[COLOR="lime"]809[/COLOR]||y|0|[COLOR="yellow"]651[/COLOR]
[COLOR="red"]9685[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||x|[COLOR="rgb(0, 255, 255)"]321[/COLOR]|0
[COLOR="red"]9685[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||x|[COLOR="rgb(0, 255, 255)"]687[/COLOR]|0
[COLOR="red"]9685[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]709[/COLOR]||y|0|[COLOR="yellow"]357[/COLOR]
[COLOR="red"]9685[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]709[/COLOR]||y|0|[COLOR="yellow"]234[/COLOR]
[COLOR="red"]2315[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||x|[COLOR="rgb(0, 255, 255)"]564[/COLOR]|0
[COLOR="red"]2315[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||x|[COLOR="rgb(0, 255, 255)"]523[/COLOR]|0
[COLOR="red"]2315[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||y|0|[COLOR="yellow"]537[/COLOR]
[COLOR="red"]2315[/COLOR]|[COLOR="rgb(255, 0, 255)"]98[/COLOR]|[COLOR="lime"]809[/COLOR]||y|0|[COLOR="Yellow"]535[/COLOR]
It's a nightmare! Now I gotta try to fix it!
# 3  
Old 09-25-2011
Power

I'm sorry if u r confused with the post.SmilieSmilie.... I have changed the colour so that you could understand my requirement.
# 4  
Old 09-25-2011
Is that color is essential?? because we cant able to understand your requirement??
# 5  
Old 09-25-2011
Hi, see if this works:
Code:
sed '$d;s/.......\(....\).\(..\)\(...\)...\(...\)....\(...\).*/\1|\2|\3||x|\4|0\n\1|\2|\3||y|0|\5/' infile

Code:
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


Last edited by Scrutinizer; 09-25-2011 at 06:43 AM.. Reason: shorter
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 09-25-2011
Power

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?
# 7  
Old 09-25-2011
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 Smilie
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux convert Comma delimited file to pipe

I have file in linux with comma delimited and string fields in double quotations ", I need to convert them to pipe delimiter please share your inputs. Example: Input: "2017-09-30","ACBD,TVF","01234",NULL,18,NULL,"686091802","BANK OF ABCD, LIMITED, THE",790456 Output: ... (4 Replies)
Discussion started by: shieksir
4 Replies

2. Shell Programming and Scripting

Convert pipe demilited file to vertical tab delimited

Hi All, How can we convert pipe delimited ( or comma ) file to vertical tab (VT) delimited. Regards PK (4 Replies)
Discussion started by: prasson_ibm
4 Replies

3. Shell Programming and Scripting

UNIX/PERL script to convert XML file to pipe delimited format

Hello, I need to get few values from a XML file and output needs to be written in another file with pipe delimited format. The Header & Footer of the Pipe Delimited file will be constant. The below is my sample XML file. I need to pull the values in between the XML tags <Operator_info to... (15 Replies)
Discussion started by: karthi1305561
15 Replies

4. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

5. Shell Programming and Scripting

How to convert space&tab delimited file to CSV?

Hello, I have a text file with space and tab (mixed) delimited file and need to convert into CSV. # cat test.txt /dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST /dev/rmt/tsmmt37 ... (6 Replies)
Discussion started by: prvnrk
6 Replies

6. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

7. Shell Programming and Scripting

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

8. Shell Programming and Scripting

Convert CSV file (with double quoted strings) to pipe delimited file

Hi, could some help me convert CSV file (with double quoted strings) to pipe delimited file: here you go with the same data: 1,Friends,"$3.99 per 1,000 listings",8158here " 1,000 listings " should be a single field. Thanks, Ram (8 Replies)
Discussion started by: Ram.Math
8 Replies

9. Shell Programming and Scripting

convert a pipe delimited file to a':" delimited file

i have a file whose data is like this:: osr_pe_assign|-120|wg000d@att.com|4| osr_evt|-21|wg000d@att.com|4| pe_avail|-21|wg000d@att.com|4| osr_svt|-11|wg000d@att.com|4| pe_mop|-13|wg000d@att.com|4| instar_ready|-35|wg000d@att.com|4| nsdnet_ready|-90|wg000d@att.com|4|... (6 Replies)
Discussion started by: priyanka3006
6 Replies

10. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 Replies
Login or Register to Ask a Question