The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding Multiple Lines to Multiple Files dayinthelife Shell Programming and Scripting 2 06-04-2008 08:50 AM
command for selecting specific lines from a script gardasgangadhar UNIX for Dummies Questions & Answers 1 05-13-2008 02:29 AM
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 08:08 AM
Shell Script to read specific lines in a file varshanswamy Shell Programming and Scripting 5 08-22-2005 04:12 PM
Shell Script for searching files with date as filter kanakaraj_s Shell Programming and Scripting 3 05-14-2002 08:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-16-2007
I-1 I-1 is offline
Registered User
 

Join Date: Feb 2007
Posts: 11
need help--script to filter specific lines from multiple txt files

Hi folks,

- I have 800 txt files
- those files are cisco router configs

Code:
router1.txt 
router2.txt
...
router800.txt
I want to accomplish the following:
- I want to have a seperate file with all the filenames that I want to process
- I want a script that goes trough all those filenames and pick out the "access-list" lines
- I want that this output is written to a separate file

I allready figured out how to get the ""access-list" lines out of 1 txt document:

Code:
#grep access-list /router/router1.txt
I have no clue how I should start.

Thanks,
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
while read file
do
     grep "access-list" $file >> tgt_file
done < file_lst
file_lst contains the file names
Reply With Quote
  #3 (permalink)  
Old 02-16-2007
I-1 I-1 is offline
Registered User
 

Join Date: Feb 2007
Posts: 11
thanks ...

This is really great !!! :-)
Reply With Quote
  #4 (permalink)  
Old 02-16-2007
I-1 I-1 is offline
Registered User
 

Join Date: Feb 2007
Posts: 11
how do I achieve that between each file I put in something like this:


==============================================
router1.txt
==============================================
access-list 1 ................
access-list 2 ................


==============================================
router2.txt
==============================================
access-list 1 ................
access-list 2 ................
Reply With Quote
  #5 (permalink)  
Old 02-16-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,564
Code:
awk 'FNR==1{printf "===============\n%s\n===============\n",FILENAME}
/access-list/' router*.txt

Use nawk on Solaris.
Reply With Quote
  #6 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
while read file
do
     echo "=============================================="
     echo "$file"
     echo "=============================================="
     grep "access-list" $file >> tgt_file
     echo
     echo
done < file_lst
Reply With Quote
  #7 (permalink)  
Old 02-16-2007
I-1 I-1 is offline
Registered User
 

Join Date: Feb 2007
Posts: 11
Hi,

What if I dont use solaris?
Is there another way?

Thanks,
I-1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0