Can sed do this?

Posted on 1998-07-06
Last Modified: 2010-04-21
I have a csv file like this:
data is delimited by comma, how can I filter out the first and third data on each line
and save into a seperate line?
Question by:xz02
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
LVL 84

Expert Comment

ID: 2008492
is this what you mean?

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

Expert Comment

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

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

Accepted Solution

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

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

Expert Comment

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

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 (, 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