search information in multiple files and save in new files | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

search information in multiple files and save in new files

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
andreia andreia is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 31 January 2013, 6:55 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
search information in multiple files and save in new files

hi everyone,

im stuck in here with shell can you help me??

i have a directory with alot files (genbank files ... all ended in .gbk ) more than 1000 for sure ... and i want to read each one of them and search for some information and if i found the right one i save in new file with new name.

i already get try for loops and no sucess

well for search the information i get it right :

awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}'


i only cant read each file and save in news!


please help me i will give you a candy
Sponsored Links
    #2  
Old 10-23-2012
bartus11's Avatar
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 20 October 2014, 5:22 PM EDT
Posts: 3,710
Thanks: 7
Thanked 1,142 Times in 1,113 Posts

Code:
awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}' *.gbk >> new_file

Sponsored Links
    #3  
Old 10-23-2012
andreia andreia is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 31 January 2013, 6:55 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
sorry dont work out

and its for all files .gbk that i found Equinodermata inside save in different file not all together but its ok ... thanks for your help
    #4  
Old 10-23-2012
bartus11's Avatar
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 20 October 2014, 5:22 PM EDT
Posts: 3,710
Thanks: 7
Thanked 1,142 Times in 1,113 Posts
Should this new file be in the same directory as the old one?
Sponsored Links
    #5  
Old 10-23-2012
andreia andreia is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 31 January 2013, 6:55 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
well this is not really important ... but yes could be in same directory
Sponsored Links
    #6  
Old 10-23-2012
bartus11's Avatar
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 20 October 2014, 5:22 PM EDT
Posts: 3,710
Thanks: 7
Thanked 1,142 Times in 1,113 Posts
Try:
Code:
for file in *.gbk; do
  awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}' $file > new_$file
done

Sponsored Links
    #7  
Old 10-23-2012
msabhi's Avatar
msabhi msabhi is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 2 November 2013, 1:26 AM EDT
Location: In books/UNIX.com
Posts: 177
Thanks: 16
Thanked 61 Times in 60 Posts

Code:
awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0 > FILENAME"_found"}' *gbk

your search patterns if found in a file say something.gbk, will be written into a new unique file something.gbk_found
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
Search & Replace: Multiple Strings / Multiple Files spacegoose Shell Programming and Scripting 2 10-16-2012 08:17 PM
reading information from a table and apply a command on multiple files @man Shell Programming and Scripting 5 10-02-2012 11:35 AM
extracting information from multiple files houkto Shell Programming and Scripting 4 11-15-2011 02:51 PM
Search multiple patterns in multiple files vsachan Shell Programming and Scripting 10 01-26-2011 04:48 PM
Merging information from multiple files to a single file crunchie Shell Programming and Scripting 4 11-11-2010 05:19 AM



All times are GMT -4. The time now is 11:46 PM.