Solved

how to remove double quotes from a file

Posted on 2014-12-15
9
108 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 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 23

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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now