• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

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.
0
xz02
Asked:
xz02
  • 2
1 Solution
 
ozoCommented:
is this what you mean?

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

sed -e h -e 's/[^,]*,\([^,]*\),[^,]*/\1/p' -e g -e 's/,[^,]*,/,/'
0
 
braveheartCommented:
Or using awk:

awk -F, '{print $1,$3}' < infile > outfile
0
 
harrauerCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now