LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-28-2012, 08:42 PM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 167

Rep: Reputation: 15
Replace a field in quotes within a csv file


I have a csv file which contains 1 field that has quotes. The content in that field changes all the time but is always in double quotes. ie "blah"

I could like to replace that field with 123 or just blank.

Code:
abc,"def",ghi
How do I go about this. Tried sed find replace but since the content within the quotes changes, I probably need to use a delimiter or marker?

Thanks.
 
Old 05-28-2012, 08:53 PM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,067

Rep: Reputation: 284Reputation: 284Reputation: 284
Try this:
Code:
echo 'abc,"def",ghi' | sed 's/".*"/123/'
Daniel B. Martin
 
Old 05-29-2012, 12:21 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,439

Rep: Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879
You didn't indicate whether or not you need to keep the quotes around the new value?
 
Old 05-29-2012, 01:10 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by grail View Post
You didn't indicate whether or not you need to keep the quotes around the new value?
.. or whether the quoted strings include double quotes, perhaps by adjacent double quotes ("") or backslash escaping (\").
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
replace line in CSV file and rename file connected to that name wademac Linux - Newbie 3 07-15-2009 01:09 PM
Bash or PHP: Split csv file based on field value? guest Programming 4 02-06-2009 12:57 AM
AWK: change a particular field in a csv file help help help!!!! haydar68 Programming 20 08-03-2008 01:10 AM
Removing quotes from a CSV file with Perl Grafbak Programming 5 07-25-2006 03:23 AM


All times are GMT -5. The time now is 02:36 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration