Solved

Can sed do this?

Posted on 1998-07-06
4
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
nodeip 9 97
Restore XenServer VM with only dd image of LVM snapshot 3 269
Access Required to Read Linux Security Settings and User Permissions 13 158
centos commands 6 117
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

734 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