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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix or Linux Image 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 Unix or Linux Image

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 Unix or Linux Image i will give you a candy Unix or Linux Image
Sponsored Links
    #2  
Old Unix and Linux 10-23-2012
bartus11's Unix or Linux Image
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 19 March 2015, 6:45 PM EDT
Posts: 3,733
Thanks: 7
Thanked 1,151 Times in 1,121 Posts

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

Sponsored Links
    #3  
Old Unix and Linux 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 Unix or Linux Image

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 Unix or Linux Image
    #4  
Old Unix and Linux 10-23-2012
bartus11's Unix or Linux Image
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 19 March 2015, 6:45 PM EDT
Posts: 3,733
Thanks: 7
Thanked 1,151 Times in 1,121 Posts
Should this new file be in the same directory as the old one?
Sponsored Links
    #5  
Old Unix and Linux 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 Unix and Linux 10-23-2012
bartus11's Unix or Linux Image
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 19 March 2015, 6:45 PM EDT
Posts: 3,733
Thanks: 7
Thanked 1,151 Times in 1,121 Posts
Try:
Code:
for file in *.gbk; do
  awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}' $file > new_$file
done

Sponsored Links
    #7  
Old Unix and Linux 10-23-2012
msabhi's Unix or Linux Image
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 12:23 AM.