How to extract subset file from dataset? | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

How to extract subset file from dataset?

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-04-2013
sajmar sajmar is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 7 November 2013, 10:24 PM EST
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
How to extract subset file from dataset?

Hello
I have a data set which looks like this :


Code:
progeny      sire          dam        gender
12                  1             3                M
13                  2             4                F
14                  2              5               F
15                  6              5               M

I need a subset data which separate the gender (M and F) to two files.
I want something like this:
file 1 output:

Code:
progeny      sire          dam        gender
13                  2             4                F
14                  2              5               F

file2 output:

Code:
progeny      sire          dam        gender
12                  1             3                M
15                  6              5               M

Thanks

Moderator's Comments:
Use code tags!
Sponsored Links
    #2  
Old 09-04-2013
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 28 November 2014, 4:08 PM EST
Location: Saskatchewan
Posts: 19,944
Thanks: 848
Thanked 3,422 Times in 3,207 Posts

Code:
awk 'NR==1 { print > "M" ; print > "F"; next }
{ print > $4 }' inputfile

The Following User Says Thank You to Corona688 For This Useful Post:
sajmar (09-04-2013)
Sponsored Links
    #3  
Old 09-04-2013
sajmar sajmar is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 7 November 2013, 10:24 PM EST
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688 View Post
Code:
awk 'NR==1 { print > "M" ; print > "F"; next }
{ print > $4 }' inputfile

@ Corona
Thanks for your suggestion. However, this command do not solve my problem.
    #4  
Old 09-04-2013
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 28 November 2014, 4:08 PM EST
Location: Saskatchewan
Posts: 19,944
Thanks: 848
Thanked 3,422 Times in 3,207 Posts
In what way did it not solve your problem? Be specific or I won't know what problem to fix.
Sponsored Links
    #5  
Old 09-04-2013
sajmar sajmar is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 7 November 2013, 10:24 PM EST
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688 View Post
In what way did it not solve your problem? Be specific or I won't know what problem to fix.
@ COrona
To be clear my problem, I have a data set :

Code:
progeny            sire          dam        gender 
12                             1                  3                     M 
13                             2                  4      F 
14                             2                   5                    F 
15                             6      5                   M

I want the subset data based on selecting the gender which looks like this:

Code:
progeny            sire          dam        gender 
13                           2                   4                      F 
14                           2                    5                     F


Last edited by Scrutinizer; 09-08-2013 at 07:30 AM.. Reason: code tags
Sponsored Links
    #6  
Old 09-04-2013
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 28 November 2014, 4:08 PM EST
Location: Saskatchewan
Posts: 19,944
Thanks: 848
Thanked 3,422 Times in 3,207 Posts
That is what my suggestion does, yes.

In what way does it not work for you? Be specific. What exactly did you do, and what precisely happened?
Sponsored Links
    #7  
Old 09-04-2013
sajmar sajmar is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 7 November 2013, 10:24 PM EST
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688 View Post
That is what my suggestion does, yes.

In what way does it not work for you? Be specific. What exactly did you do, and what precisely happened?
@ Corona:
When I run the program, it gives me the empty file.

Code:
awk 'NR==1 { print > "M" ; print > "F"; next }{ print > $4 }' aa > bb


Last edited by Scrutinizer; 09-08-2013 at 07:31 AM.. Reason: code tags
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
Random selection of subset of sample from file biopsy UNIX for Dummies Questions & Answers 7 11-29-2012 10:50 AM
how to get a subset of such a file forevertl UNIX for Dummies Questions & Answers 2 07-30-2012 05:01 PM
How to remove a subset of data from a large dataset based on values on one line davegen Shell Programming and Scripting 2 11-24-2011 08:12 AM
flarecreate for zfs root dataset and ignore multiple dataset uxravi Solaris 0 09-13-2011 02:49 PM
How to extract a subset from a huge dataset cliffyiu Shell Programming and Scripting 3 03-13-2010 01:54 PM



All times are GMT -4. The time now is 05:34 PM.