Solved

how to remove double quotes from a file

Posted on 2014-12-15
9
114 Views
Last Modified: 2015-01-07
How would I remove double quotes from a file

For example:
,XXXX,BBBBBB,"CCCCC",444444,"999999"


Thanks in advance
0
Comment
Question by:bje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 40500758
sed -i.bak 's/"//g' filename

The above will create a backup file "filename.bak" and change the original file "filename" "in place".
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40500796
To change just a single string (as the example in your question) just do

echo ',XXXX,BBBBBB,"CCCCC",444444,"999999"' | tr -d '"'

'"' after "-d" is: "single_quote double_quote single_quote" (without any intervening spaces).

With variables:

STRING=',XXXX,BBBBBB,"CCCCC",444444,"999999"'
NEWSTRING=$(echo $STRING | tr -d '"')
or even
STRING=$(echo $STRING | tr -d '"')
0
 
LVL 25

Expert Comment

by:NVIT
ID: 40500921
RmvQuotes.txt:
XXXX,BBBBBB,"CCCCC",444444,"999999"
XXXX,"BBBBBB","EE",444444,"XX"

Open in new window


RmvQuotes.bat:
@echo off
for /f "tokens=*" %%a in (RmvQuotes.txt) do (call :DoIt %%a %%b %%c %%d %%e)
goto :EOF

:DoIt
echo %~1,%~2,%~3,%~4,%~5

Open in new window

0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 

Author Comment

by:bje
ID: 40500967
Thanks for the solutions.

Once the double quotes are removed will need to look for at the beginning of the line and look for  ,H and when found replace the  , with a TR

Have this,
sed 's/^,H/ /^,H\TR/g  < filename

How do you combine them?

Thanks
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 40500983
Do you mean the literal string "TR" or something else, like a control character?

Replace "," with "TR" and combine this with the other command:

sed -i.bak 's/"//g;s/^,H/TRH/' filename

",H" will become "TRH" this way. Is it that what you desire?
0
 

Accepted Solution

by:
bje earned 0 total points
ID: 40501586
yes. each row that matches would start wtih TRH.

Thanks
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40501603
So use this solution (already posted above, but here it is again):

sed -i.bak 's/"//g;s/^,H/TRH/' filename
0
 

Author Comment

by:bje
ID: 40524181
I am trying to mark the two open questions complete, however it is not saving this information.  how to I close these tickets.  I have marked the solution accepted and award points and clicked on submit.

Thanks
0
 

Author Closing Comment

by:bje
ID: 40535215
Thanks
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question