LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-31-2014, 05:38 AM   #1
srinureddy
LQ Newbie
 
Registered: Oct 2014
Posts: 11

Rep: Reputation: Disabled
csv file modification


Hi.. i am new to the Linux. i have a task like this

i have a csv file like this

"101","ddd","ss"
"102","ssa","dee"
"103","dss"Ds","dsd"sds"
"104","sd"sds","dsds"
"105","dsd","dsdS"

in this i want to replace double quotes with 2 double quotes.

note: in this we used comma as a column delimiter and every column data enclosed by double quotes so we replace only only data contain double quotes.

ex:

"104","sd"sds","dsds"

i want to change li this

"104","sd""sds","dsds"
 
Old 10-31-2014, 06:36 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You can use sed for this:
Code:
sed s/\"/\"\"/g
 
Old 10-31-2014, 07:49 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Try this for single double quote with two double quotes replacement.
Code:
sed -e 's/^\"/\x98/g' -e 's/\"$/\x98/g' -e 's/\",\"/\x99/g' -e 's/\"/\"\"/g' -e 's/\x99/\",\"/g' -e 's/\x98/\"/g' filename.csv
 
Old 10-31-2014, 06:37 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
or even any text editor like gedit or kate

and use the find/replace option
you can even use a spreed sheet program like Openoffices "calc" ( aka Excel )

depending on the size of the file
for small files a spread sheet works great
for large files 10's of megs or gigs in size "sed" is great
 
Old 10-31-2014, 09:57 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Maybe try and ask a question just once and don't open another because the other one is not going the direction you want.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] A challenging script - Replace field of CSV file based on another CSV file arbex5 Programming 11 06-12-2013 06:56 AM
[SOLVED] How to script csv editing? Remove rows from csv file that do not contain certain text ingram87 Linux - Software 9 08-03-2012 12:45 PM
Parse a CSV file output to text file beto Linux - Newbie 3 04-25-2012 08:45 AM
replace line in CSV file and rename file connected to that name wademac Linux - Newbie 3 07-15-2009 01:09 PM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration