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 06-28-2012
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
How to fetch files right below based on some matching criteria?

I have a requirement where in i need to select records right below the search criteria

Code:
qwertykeyboard  white
10 20 30
30 40 50
60 70 80
qwertykeyboard  black
40 50 60
70 90 100

qwertykeyboard and white are headers separated by a tab.

when i execute my script..i would be searching to bring whatever records are beneath white and black...Also, can i get these records into 2 files
1 for white
and 1 for black

---------- Post updated at 10:27 PM ---------- Previous update was at 09:18 PM ----------

Any answers??????

---------- Post updated 06-28-12 at 12:48 PM ---------- Previous update was 06-27-12 at 10:27 PM ----------

Have i posted the Question in the correct forum????

Last edited by vbe; 06-27-2012 at 11:50 AM.. Reason: mot all the text in code tags!! it becomes useless!
Sponsored Links
    #2  
Old 06-28-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 955 Times in 934 Posts
Can you post desired output for that sample data?
Sponsored Links
    #3  
Old 06-28-2012
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Sure
I want file 1 ie white.txt to have

Code:
10 20 30
30 40 50
60 70 80

and file 2 ie black.txt to have


Code:
40 50 60
70 90 100


Last edited by Scrutinizer; 06-28-2012 at 03:24 AM.. Reason: code tags
    #4  
Old 06-28-2012
Registered User
 
Join Date: Mar 2011
Location: Neverland
Posts: 59
Thanks: 12
Thanked 11 Times in 10 Posts

Code:
 
 sed  -n '/qwertykeyboard  white/,/qwertykeyboard  black/p'  < inputfile  | sed '1d'| sed '$d' > file1
 sed  '/qwertykeyboard  white/,/qwertykeyboard  black/d' < inputfile > file2

let me know if you face any issue
Sponsored Links
    #5  
Old 06-28-2012
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Awesome..Thanx a lot!!
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
How to select files based on a criteria? saggiboy10 UNIX for Dummies Questions & Answers 7 06-20-2012 10:46 AM
Archive files to different target folders based on criteria kmsekhar Shell Programming and Scripting 2 08-30-2011 06:18 AM
Script move and rename based on matching criteria braidomik Shell Programming and Scripting 3 08-26-2008 11:35 AM
Simultaneous searching for files (names matching certain criteria) in several directo Hopeful AIX 0 02-13-2008 01:31 PM
deleting files and folders matching criteria H3001 Shell Programming and Scripting 4 06-25-2007 08:20 AM



All times are GMT -4. The time now is 11:34 AM.