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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java core in Solaris 10 1 296
change HISTFILE for root user on AIX 3 87
Shell Script on AIX 7 116
remove one line from a file in solaris 8 43
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…
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.

821 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