Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-04-2012
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Command line / script option to filter a data set by values of one column

Hi all!

I have a data set in this tab separated format : Label, Value1, Value2

An instance is "data.txt" :
0 1 1
-1 2 3
0 2 2

I would like to parse this data set and generate two files, one that has only data with the label 0 and the other with label -1, so my outputs should be, for example :

data0.txt
0 1 1
0 2 2

and data-1.txt
-1 2 3

These are large datasets, and I do not know in advance how many labels there are. Assuming the labels are l1...ln, I would like the outputs stored in data_<label>.txt where <label> is one of l1...ln


Can someone here suggest a quick way to script / command-line this?

Thanks in advance!
Sponsored Links
    #2  
Old 07-04-2012
itkamaraj's Avatar
^Kamaraj^
 
Join Date: Apr 2010
Posts: 3,025
Thanks: 33
Thanked 647 Times in 625 Posts

Code:
awk '{file="data"$1".txt";print $0 > file}' data.txt

use code tag for posting the data and scripts

http://www.unix.com/how-post-unix-li...code-tags.html
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading command line arguments and setting up values if option not provided kristinu Programming 2 03-22-2012 09:16 PM
What is a menu or command line option driven script? kpddong UNIX for Dummies Questions & Answers 2 12-09-2010 11:58 AM
Filter and migrate data from row to column shah09 Shell Programming and Scripting 5 05-31-2010 08:24 AM
How to change values in certain column only in every line (any script) luna_soleil Shell Programming and Scripting 3 05-17-2010 12:45 PM
repeated column data filter and make as a row vasanth_vadalur Shell Programming and Scripting 2 06-16-2009 07:01 AM



All times are GMT -4. The time now is 10:50 AM.