Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to remove double quotes from a file

Posted on 2014-12-15
9
Medium Priority
?
115 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 2000 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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 

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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Utilizing an array to gracefully append to a list of EmailAddresses
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…

660 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