Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to remove double quotes from a file

Posted on 2014-12-15
9
Medium Priority
?
116 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
  • 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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

886 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