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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 36
ftpcommand 2 56
How to calculate the current use of PVU on my TSM server. 4 59
problem creating new luks volume on new VM disk 5 77
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 …
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

911 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

19 Experts available now in Live!

Get 1:1 Help Now