comma replaced with pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comma replaced with pipe
# 1  
Old 07-26-2010
comma replaced with pipe

Code:
 
Source data:
 
"123","aaa bbb CCC","12000"
"134","HHH,bbc","13000"
i have a delimited[camma] file. i want to replace with the pipe.The sed command is not working for replacing a delimeter.

Code:
 
Command :
sed s/\,/\|/g filename

Code:
 
Output : When i run the command it is replacing the columns value too.
"123"|"aaa bbb CCC"|"12000"
"134"|"HHH|bbc"|"13000"
 
Actual output required 
"123"|"aaa bbb CCC"|"12000"
"134"|"HHH,bbc"|"13000"

# 2  
Old 07-26-2010
Code:
sed 's/"[ \t]*,[ \t]*"/"|"/g' file

# 3  
Old 07-26-2010
your code changes to all commas.

you can try this Smilie
Code:
# sed 's/","/"|"/g' al

# 4  
Old 07-26-2010
thanks for update..
It is really fine.

Source file 2GB.when i use sed command it is taking 1hr 50mins to complete the process. As i can see the foarms, awk command will execute faster then sed command.


I have tried with the awk. it is not giving proper output.

Code:
 echo "abc","bbc,cbs"| awk '{gsub(" ","");gsub("\"$", "");gsub("\",\"", "|");gsub(",\"","|")}1'


output
Code:
 abc,bbc,cbs


Last edited by Scott; 07-26-2010 at 05:17 AM..
# 5  
Old 07-26-2010
Hi,

Try this,
Code:
awk '{gsub (",\"","|\"",$0);print}' inputfile

# 6  
Old 08-11-2010
Thanks for the suggestion.

I have taken the replacing delimeter as ~.

It is working fine all the records except couple of records.

Source file:
Cust_information.txt
"1000","customer,product"
"1000","customer,sales,"

Code:
awk '{gsub (",\"","~\"",$0);print}' Cust_information.txt

I am facing issue with second record, delimeter is replacing with in the double quotes
Output:
"1000"~"customer,product"
"1000"~"customer,sales~"

Actual Output:
"1000"~"customer,product"
"1000"~"customer,sales,"



Any help greatly appricated.
# 7  
Old 08-11-2010
Code:
awk '{gsub ("\",\"","\"~\"",$0);print}' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

2. 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

3. Shell Programming and Scripting

Broken pipe symbol replaced with <A6><A6>

hi, i am copying an xml file from windows to linux server using filezilla&winscp. xml file contains ¦¦ symbols, after copying xml file to server ¦¦ is replaced with <A6><A6>. tried with copying xml files from windows in ascii&binary but no luck. please suggest. thanks (1 Reply)
Discussion started by: Satyak
1 Replies

4. Shell Programming and Scripting

How to cut a pipe delimited file and paste it with another file to form a comma separated outputfile

Hello ppl I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt Now I have to join (paste in unix) this A2.txt with external file A3.txt to form output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Discussion started by: etldev
25 Replies

5. Shell Programming and Scripting

Sed, replace comma with pipe. but ignore qoutes

hi, I am trying to replace comma with pipe, but the issue is that i want to ignore the commas inside qoutes. for example: i have file with the string: 1,"2,3",4,"5","6,7" the result should be : 1|"2,3"|4|"5"|"6,7" i trying to use sed and awk (match function) for that, but i did not... (4 Replies)
Discussion started by: gabik
4 Replies

6. Shell Programming and Scripting

Linux - Script to generate the output delimited by Comma/Pipe

Hi All, I have a requirement where I need to go to a directory, list all the files that start with person* (for eg) & read the most recent file from the list of files. While browsing through the forum, i found that the command ls -t will list the files. I am trying to generate the output... (1 Reply)
Discussion started by: dsfreddie
1 Replies

7. Shell Programming and Scripting

Replace pipe <|> with comma <,> in a column

Hi All Gurus, I need to replace a pipe <|> with a comma <,> in a few columns with pipe delimited file. The column name are fixed for the replacement of comma <,>. For below example, Col3, Col6 and Col8 are columns need to replace with comma <,> if any pipe encountered. example:... (14 Replies)
Discussion started by: agathaeleanor
14 Replies

8. Shell Programming and Scripting

Converting comma separated to pipe delimited file

Hi, I came across a very good script to convert a comma seperated to pipe delimited file in this forum. the script serves most of the requirement but looks like it does not handle embedded double quotes and commas i.e if the input is like 1234, "value","first,second", "LDC5"monitor",... (15 Replies)
Discussion started by: anijan
15 Replies

9. Shell Programming and Scripting

Trimming fields for comma or pipe seperated file

I have file like this FileA: abc , "helloworld" , america def,asia, japan ghi, africa, ipl Output Needed: abc,"helloworld",america def,asia,japan ghi,africa,ipl I would like to implement using awk. I want to trim each field for its leading and trailing spaces. (7 Replies)
Discussion started by: pinnacle
7 Replies

10. Shell Programming and Scripting

To Replace comma with Pipe inside double quotes

Hi, I have a requirement to replace the comma's inside the double quotes. The comma's inside the double quotes will get changed dynamically. Input Record: "Washington, DC,Prabhu,aju",New York Output Record: "Washington| DC|Prabhu|aju",New York I tried with the below command but it... (3 Replies)
Discussion started by: prabhutkl
3 Replies
Login or Register to Ask a Question