LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-03-2010, 02:01 AM   #1
chedog
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Rep: Reputation: 0
sed


I have been using sed to manulate a csv file but i have one problem that I can't solve.
the csv file has many line and many columns

if in a particular line column 2 has a certain value I want to replace that value with the value in column 5 in the same line.

help please I have searche for hours with this one
 
Old 02-03-2010, 02:45 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

I think you should have a look at awk instead of sed. Awk is more equiped to work with columns and separated values. Here's a link to full documentation Sed & Awk. You could also consult the man pages for awk:
Code:
man awk
Kind regards,

Eric
 
Old 02-03-2010, 04:10 AM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Yes, do try using awk:
http://www.grymoire.com/Unix/Awk.html
 
Old 02-03-2010, 04:30 AM   #4
bmxcess
Member
 
Registered: Jan 2009
Location: Brisbane, Australia
Distribution: @work:RHEL 5.4/Fedora 13, @home:slack64-current,ubuntu lynx studio
Posts: 65

Rep: Reputation: 19
Using sed for csv is perfectly valid. The sedfaq should be on your system with sed. Search for csv. In my distro under /usr/share/doc/sed-4.2.1/sedfaq.txt.gz

HTH
 
Old 02-03-2010, 06:34 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
No "sedfaq" on my system---never seen such a thing. But a really good tutorial is here: http://www.grymoire.com/Unix/Sed.html

BUT--with data in columns--awk is probably easier.
 
Old 02-03-2010, 08:49 AM   #6
bmxcess
Member
 
Registered: Jan 2009
Location: Brisbane, Australia
Distribution: @work:RHEL 5.4/Fedora 13, @home:slack64-current,ubuntu lynx studio
Posts: 65

Rep: Reputation: 19
For most applications I'd agree. FWIW the Sed FAQ can also be found here: http://sed.sourceforge.net/sedfaq.html
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed - use sed to replace multiple instances from "x" to "y" in a line mrodmac Linux - General 4 02-02-2010 11:37 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:45 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