Solved

Can sed do this?

Posted on 1998-07-06
4
194 Views
Last Modified: 2010-04-21
I have a csv file like this:
1.3,2.4,4.5
4.0,6.77,3.21
.....
data is delimited by comma, how can I filter out the first and third data on each line
and save into a seperate line?
Thanks.
0
Comment
Question by:xz02
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2008492
is this what you mean?

sed -e 's/,[^,]*,/,/' < csvfile > seperatefile
0
 
LVL 84

Expert Comment

by:ozo
ID: 2008493
Or do you mean something more like this?

sed -e h -e 's/[^,]*,\([^,]*\),[^,]*/\1/p' -e g -e 's/,[^,]*,/,/'
0
 
LVL 3

Accepted Solution

by:
braveheart earned 50 total points
ID: 2008494
Or using awk:

awk -F, '{print $1,$3}' < infile > outfile
0
 

Expert Comment

by:harrauer
ID: 2008495
I would do a

cat infile | cut -d, -f1,3 | tr " " "\012" >outfile

which should filter out the first and third column separated by
commas and separate them afterwards by a newline...
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

746 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

14 Experts available now in Live!

Get 1:1 Help Now