The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 11:50 AM
command for selecting specific lines from a script gardasgangadhar UNIX for Dummies Questions & Answers 1 05-13-2008 05:29 AM
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 11:08 AM
Shell Script to read specific lines in a file varshanswamy Shell Programming and Scripting 5 08-22-2005 07:12 PM
Shell Script for searching files with date as filter kanakaraj_s Shell Programming and Scripting 3 05-14-2002 11:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-16-2007
I-1 I-1 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 26
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,
  #2 (permalink)  
Old 02-16-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

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

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

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

Join Date: Feb 2007
Posts: 26
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 ................
  #5 (permalink)  
Old 02-16-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
awk 'FNR==1{printf "===============\n%s\n===============\n",FILENAME}
/access-list/' router*.txt

Use nawk on Solaris.
  #6 (permalink)  
Old 02-16-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

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

Join Date: Feb 2007
Posts: 26
Hi,

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

Thanks,
I-1
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0