need help--script to filter specific lines from multiple txt files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help--script to filter specific lines from multiple txt files
# 1  
Old 02-16-2007
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  
Old 02-16-2007
Code:
while read file
do
     grep "access-list" $file >> tgt_file
done < file_lst

file_lst contains the file names
# 3  
Old 02-16-2007
thanks ...

This is really great !!! :-)
# 4  
Old 02-16-2007
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  
Old 02-16-2007
Code:
awk 'FNR==1{printf "===============\n%s\n===============\n",FILENAME}
/access-list/' router*.txt


Use nawk on Solaris.
# 6  
Old 02-16-2007
Code:
while read file
do
     echo "=============================================="
     echo "$file"
     echo "=============================================="
     grep "access-list" $file >> tgt_file
     echo
     echo
done < file_lst

# 7  
Old 02-16-2007
Hi,

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

Thanks,
I-1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter lines based on values at specific positions

hi. I have a Fixed Length text file as input where the character positions 4-5(two character positions starting from 4th position) indicates the LOB indicator. The file structure is something like below: 10126Apple DrinkOmaha 10231Milkshake New Jersey 103 Billabong Illinois ... (6 Replies)
Discussion started by: kumarjt
6 Replies

2. Shell Programming and Scripting

Help with shell script - filter txt file full of ips

Hello again gentlemen. I would like to make a shell script to 'optimize' a plain text full of IPs. Let's suppose to have this text file: 1.192.63.253-1.192.63.253 1.0.234.46/32 1.1.128.0/17 1.116.0.0/14 1.177.1.157-1.177.1.157 1.23.22.19 1.192.61.0-1.192.61.99 8.6.6.6 I want to... (2 Replies)
Discussion started by: accolito
2 Replies

3. Shell Programming and Scripting

awk to filter multiple lines

Hi. I need to filter lines based upon matches in multiple tab-separated columns. For all matching occurrences in column 1, check the corresponding column 4. IF all column 4 entries are identical, discard all lines. If even one entry in column 4 is different, then keep all lines. How can I... (5 Replies)
Discussion started by: owwow14
5 Replies

4. Shell Programming and Scripting

Removing specific lines from script files.

Hello, Activity to perform: 1. Find all of the "*.tmp" files in a given user directory 2. Determine which ones have "find" in them. 3. Replace the "find sequence" of commands with a "list set" of commands. Example: Original file: -------------- define lastn1 = "A" define... (7 Replies)
Discussion started by: manishdivs
7 Replies

5. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

6. UNIX for Dummies Questions & Answers

redirecting arguments in a script to multiple lines in a .txt file

Ok hope my vocab is right here, i'm trying to write multiple sets of arguments to another file for example: I have a script that accepts four arguments and sends them to a another file $write.sh it then out in so the file receiver.txt would contain this: it then out in what... (2 Replies)
Discussion started by: austing5
2 Replies

7. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

8. Shell Programming and Scripting

filter out a sequence from multiple lines line

Hi, I have an unwanted string at random lines of my verilog (*.v) file. (* abccddee *) input A; (* xyz *) input B; (* 1234 *) output C; I want a clean file like this: input A; input B; output C; the unwanted string begins with "(*" and ends with "*)" at multiple lines. Any help... (2 Replies)
Discussion started by: return_user
2 Replies

9. Shell Programming and Scripting

How to remove certain lines in multiple txt files?

Hi , I have this type of files:- BGH.28OCT2008.00000001.433155.001 BGH.28OCT2008.00000002.1552361.001 BGH.28OCT2008.00000003.1438355.001 BGH.28OCT2008.00000004.1562602.001 Inside them contains the below: 5Discounts 6P150 - Max Total Usage RM150|-221.00 P150 EPP - Talktime RM150... (5 Replies)
Discussion started by: olloong
5 Replies

10. Shell Programming and Scripting

how do I filter double lines from a txt file

Hi, I have a file with the following: access-list.txt router1 access-list 1 permit any any access-list 1 deny any any router2 access-list 2 permit any any access-list 2 deny any any router3 access-list 3 permit any any access-list 3 deny any any I want to hava an output that... (10 Replies)
Discussion started by: I-1
10 Replies
Login or Register to Ask a Question