How to remove unwanted " from string...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove unwanted " from string...
# 1  
Old 07-07-2011
How to remove unwanted " from string...

I have this Input File with extra double quotes in the middle. Please suggest how to handle this condition.

Input File:
Code:
"123985","SAW CUT CONCRETE SLAB 20"THICK",,"98.57","","EACH","N"
"204312","ARMAFLEX-1 3/8 X 3"",,"2.48","","PER FOOT","N"
"205745","MISTING HEAD HOLLOW CONE "C" TYPE","",,"4.32","","EACH","Y"
"205621","DRILL BIT FOR "WOOD" AND GLASS","",,"9.26","","EACH","N"

The extra quote from 20" from line 1, 3" from line 2, "C" from line 3 and "WOOD" from line 4 will be removed.
Desired Output:
Code:
"123985","SAW CUT CONCRETE SLAB 20THICK",,"98.57","","EACH","N"
"204312","ARMAFLEX-1 3/8 X 3",,"2.48","","PER FOOT","N"
"205745","MISTING HEAD HOLLOW CONE C TYPE","",,"4.32","","EACH","Y"
"205621","DRILL BIT FOR WOOD AND GLASS","",,"9.26","","EACH","N"

Please advice.
Thanks in advance.

Last edited by Franklin52; 07-08-2011 at 03:40 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-08-2011
This worked on the small test I ran:

Code:
sed 's/^"/~/; s/"$/~/; s/",/~,/g; s/,"/,~/g; s/"//g; s/~/"/g' in-file >out-file

It assumes that quotes to be kept are at the beginning/ending of the line, or are either preceded or trailed by a comma. It will not handle the case where something like 3" in the text is followed by a comma:

Code:
"204312","ARMAFLEX-1 3/8 X 3", NAT COLOUR",,"2.48","","PER FOOT","N"

If you have cases like this, then you'll need something a bit more robust.

Oh yea, it assumes no tildas (~) in the input!

Last edited by agama; 07-08-2011 at 12:21 AM.. Reason: clarification
# 3  
Old 07-08-2011
Thanks a LOT Smilie Agama... I will test it out and will let you know the result.
# 4  
Old 07-08-2011
Or try..
Code:
sed 's/\(,"[^",]\+\)"*\([^,"]*\)"*\([^",]*",\)/\1\2\3/g' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove leading "#" from a String

Hi Everyone, i am new to scripting and stuck in something. Query is : I have a properties file eg. data.properties. This data.properties have some values example : key1=value1 key2=value2 #key3=value3 as key3 is commented by #. so i want to write a script , that will remove # from... (3 Replies)
Discussion started by: Raj87ng
3 Replies

2. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

3. Shell Programming and Scripting

How to remove unwanted strings?

Hi Guys, Can someone give me a hand on how I can remove unwanted strings like "<Number>" and "</Number>" and retain only the numbers from the input file below. INPUT FILE: <Number>10050000</Number> <Number>1001340001</Number> <Number>1001750002</Number> <Number>100750003</Number>... (8 Replies)
Discussion started by: pinpe
8 Replies

4. Shell Programming and Scripting

Remove path string from file (string contains "/")

This is the way sed -i 's/home/$USER/.config/hello_there//g' /home/$USER/.gnomerc But, as far as I saw you cannot add any "/" in the string you want to remove.... So, what should I do in order to remove this path (which contains "/") ?:confused: (7 Replies)
Discussion started by: hakermania
7 Replies

5. Shell Programming and Scripting

Remove unwanted lines

I have a .xml file, where i need some output. The xml file is like: Code: <?******?></ddddd><sssss>234</dfdffsdf><sdhjh>534</dfdfa>......... /Code I need the output like: code 234 534 . . . /code How can i do it? (5 Replies)
Discussion started by: anupdas
5 Replies

6. Emergency UNIX and Linux Support

Remove Unwanted Libraries - optimizing

We have a huge makefile composing of inclusion of libraries, objects and system libraries to generate a binary. How do we find out that which of the libraries we can remove in the most efficient way? Doing hit and trial method is a waste of time and can during the linking with some post linking... (12 Replies)
Discussion started by: uunniixx
12 Replies

7. Shell Programming and Scripting

Remove "/" from a string

Hi, I've a string "200910/22-101010" ( this is date and time string YYYYMMDD/HHMMSS format) , how can i remove "/" and assign it to a new variable a value of 20091022 only thanks (6 Replies)
Discussion started by: rudoraj
6 Replies

8. Solaris

Remove unwanted packages

I got a system which was installed with SUNWCXall cluster installed on it and i want remove unwanted software like GMNOME, Java Desktop System, Staroffice and numerous other softwares .. i want to do an automated removal of these packages where its uninstalled by itself ..from the is there any... (4 Replies)
Discussion started by: fugitive
4 Replies

9. Shell Programming and Scripting

Remove unwanted XML Tags

I have set of sources and the respective resolution. Please advice how to resolve the same using Unix shell scripting. Source 1: ======= <ext:ContactInfo xmlns:ext="urn:AOL.FLOWS.Extensions"> <ext:InternetEmailAddress>AOL@AOL.COM</ext:InternetEmailAddress> </ext:ContactInfo> Resoultion... (1 Reply)
Discussion started by: ambals123
1 Replies

10. Shell Programming and Scripting

Remove unwanted data?

Hi Can any one help me remove the unwanted data? I would want to remove the complete event id 4910 ( the type there is INFO), that means, I have to remove starting from 7th - 19th lines. can any one of you please help? Thanks, (24 Replies)
Discussion started by: hitmansilentass
24 Replies
Login or Register to Ask a Question