Link to home
Start Free TrialLog in
Avatar of xz02
xz02

asked on

Can sed do this?

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.
Avatar of ozo
ozo
Flag of United States of America image

is this what you mean?

sed -e 's/,[^,]*,/,/' < csvfile > seperatefile
Or do you mean something more like this?

sed -e h -e 's/[^,]*,\([^,]*\),[^,]*/\1/p' -e g -e 's/,[^,]*,/,/'
ASKER CERTIFIED SOLUTION
Avatar of braveheart
braveheart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of harrauer
harrauer

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...