Computing.Net > Forums > Unix > Remove Pipe from file

Remove Pipe from file

Reply to Message Icon

Original Message
Name: Narasimha
Date: February 19, 2007 at 16:07:48 Pacific
Subject: Remove Pipe from file
OS: HP-UX
CPU/Ram: 2 GB
Model/Manufacturer: HP
Comment:

Hi all,

I have a requirement where I have to substitute a | with nothing in a file which has records of the type


This is the regular format of my file

aaa|.|bbb|.|ccc|.|ddd
eee|.|fff|.|ggg|.|hhh
iii|.|jjj|.|kkk|.|lll

Sometimes I get a | in these fieds like below (check the g|gg)


aaa|.|bbb|.|ccc|.|ddd
eee|.|fff|.|g|gg|.|hhh
iii|.|jjj|.|kkk|.|lll


Due to this my ETL fails.
Can anybody suggest how I can remove only the extra pipes in the file.
Any suggestions greatly appreciated.
Please get back if you need more clarification.

Thanks
Narasimha


Report Offensive Message For Removal


Response Number 1
Name: thepubba1
Date: February 19, 2007 at 17:21:54 Pacific
Subject: Remove Pipe from file
Reply: (edit)

Using this data and placing it into a file called data:

aaa|.|bbb|.|ccc|.|ddd
eee|.|fff|.|g|gg|.|hhh
iii|.|jjj|.|kkk|.|lll

sed s/\|//g < data

gives me this output:

aaa.bbb.ccc.ddd
eee.fff.ggg.hhh
iii.jjj.kkk.lll


Report Offensive Follow Up For Removal

Response Number 2
Name: nails
Date: February 19, 2007 at 20:23:32 Pacific
Subject: Remove Pipe from file
Reply: (edit)

If I'm understanding you correctly, your field seperator is |.| that is, a pipe symbol, a period, a pipe symbol. A stray pipe symbol messes up your data.

One way of doing this is to choose a character that is not used in the data file for a temporary separator. Then, replace |.| with the temporary seperator, delete any extraneous pipe symbols, and, finally, replace the temporary seperator with the true one:

sed 's/\|\.\|/#/g' < data.file|sed 's/\|//g' |sed 's/#/\|\.\|/g'

Maybe somebody with better regex skills than I have, can come up with a better solution.


Report Offensive Follow Up For Removal

Response Number 3
Name: Narasimha
Date: February 20, 2007 at 14:47:50 Pacific
Subject: Remove Pipe from file
Reply: (edit)

nails,

You have understood the scenario correctly.Currently I am using the same appraoch you have suggested.
Is there any other way ???


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: February 20, 2007 at 20:36:33 Pacific
Subject: Remove Pipe from file
Reply: (edit)

I realize the solution I provided is inefficient, but I still don't have any other solution.


Report Offensive Follow Up For Removal

Response Number 5
Name: Narasimha
Date: February 23, 2007 at 12:44:15 Pacific
Subject: Remove Pipe from file
Reply: (edit)

nails,

Thats the best I have got till now, Thanks!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Remove Pipe from file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge