substitute commas with pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting substitute commas with pipe
# 1  
Old 10-28-2008
substitute commas with pipe

Hi All,

I have a file that contain value below:

test,mno,mno, +asc
mno,lok,msyu,tts
test,poi,test,0,90, 3,00

i need to substitute the comma's into pipe where i used the command below

:s/,/|/g

then it change to below:

test|mnb|mno| +asc
mno|lok|msyu|tts
test|poi|test|0|90| 3|00

my objective is to change all the commas to pipe but for the 0|90 and 3|00 i want it to maintain the comma's which is 0,90 and 3,00?So any suggestion?
# 2  
Old 10-28-2008
This close to what you're after ?

Code:
#  sed 's/\([^0-9]\),\([^0-9]\)/\1|\2/g' infile
test|mno|mno| +asc
mno|lok|msyu|tts
test|poi|test,0,90, 3,00

# 3  
Old 10-28-2008
an alternative for different layout:
Code:
#  sed -e 's/,/|/g' -e 's/\([0-9]\)|\([0-9]\)/\1,\2/g' infile
test|mno|mno| +asc
mno|lok|msyu|tts
test|poi|test|0,90| 3,00

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert commas

Original content: ACACCTCAT 129 | ACACCTCAT 0 ACACCTCATX 171 | ACACCTCATX 0 ACACRESRT 0 ACACRESRT 0 ACACRESRTX 0 ... (4 Replies)
Discussion started by: loktamann
4 Replies

2. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

3. Shell Programming and Scripting

Replace field with commas with field without commas

Hey guys, I have the following text: 1,2,3,4,5,6,'NULL','when',NULL,1,2,0,'NULL' 1,2,3,4,5,6,'NULL','what','NULL',1,2,0,1 I need the same text with the word NULL without commas u know something like this: 1,2,3,4,5,6,NULL,'when',NULL,1,2,0,NULL 1,2,3,4,5,6,NULL,'what','NULL',1,2,0,1 ... (1 Reply)
Discussion started by: lmyk72
1 Replies

4. Shell Programming and Scripting

Commas within Delimeters

Hi experts, I would like a favour from you guys to get the info from 5th column which was separated by the delimeter comma ( , ) The Data file is as below:- 1,USER1,"90, TEST AVENUE, OLD ROAD",test1,124,N 2,USER2,88 TEST STREET NEW ROAD,test2,123,N The User File is as below:- USER1... (1 Reply)
Discussion started by: shenkz
1 Replies

5. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

6. Shell Programming and Scripting

Need help in removing commas

i have the below line as output from a script. I want to delete the string "," and get the output without comma, cat D* | grep "bytes free" | awk '{print $3}' | ????? output: 40,966,189,056 Desired O/P: 40966189056 (1 Reply)
Discussion started by: ali560045
1 Replies

7. Shell Programming and Scripting

replace one or more tabs with commas

Hi, Can any one tell me how to replace one or more tabs from start of the line and in between the words with commas in the file using unix commands? My actual data in the text file is as below with spaces.The spaces are not being shown in the post..please see them while replying to the post.... (1 Reply)
Discussion started by: tucs_123
1 Replies

8. UNIX for Dummies Questions & Answers

Inserting commas and replacing backslashes with commas

Hi, Newbie here. I have a file that consists of data that I want to convert to a csv file. For example: Jul 20 2008 1111 / visit home / BlackBerry8830/4.2.2 Profile/MIDP-2.0 Configuration/CLOC-1.1 VendorID/105 Jul 21 2008 22222 / add friend / BlackBerry8830/4.2.2 Profile/MIDP-2.0... (3 Replies)
Discussion started by: kangaroo
3 Replies

9. UNIX for Dummies Questions & Answers

Deletion of starting commas

There is one question. I have a string(suppose $str). If it starts with a comma(there can be more than one comma at the start),I have to remove all the commas from the beginning.So i have to check if the string starts with a comma.If it does,I have to delete all the commas which are at the start of... (1 Reply)
Discussion started by: abhinavsinha
1 Replies

10. HP-UX

count commas in a script

I've a text file which is delimeted by a comma. But there are some commas in side a quoted string. For ex: My file a1.txt contains: "ab,bef",a,b,1,2,"abcde",0, If you look at the above line, the shell script should give me a count of commas which is 7 according to the above example.... (2 Replies)
Discussion started by: obedkhan
2 Replies
Login or Register to Ask a Question