Sponsored Content
Top Forums UNIX for Dummies Questions & Answers how to find a word in a file that appears next to a given keyword Post 302450357 by gaurav1086 on Thursday 2nd of September 2010 11:45:11 AM
Old 09-02-2010
Quote:
Originally Posted by mwrg
Hi Experts,

I have a file which contains some text. i need to print the word next to a given keyword. Please help.

Ex: test.txt
Code:
 
=====================
NEXT HOST
=====================
 AEADBAS001
access-list 1 permit xxxxxxxxxxxxxx
ip access-list extended BLA_Outgoing_Filter
access-list 1 permit xxxxxxxxxxxxxx
access-list 2 permit xxxxxxxxxxxxxx

If i use the keyword "extended" it should return BLA_Outgoing_Filter

Moderator's Comments:
Mod Comment Having 25 posts you should be familiar using code tags.

Hello,

Code:
gaurav@localhost:~/unix$ cat test2.txt 
=====================
NEXT HOST
=====================
 AEADBAS001
access-list 1 permit xxxxxxxxxxxxxx
ip access-list extended BLA_Outgoing_Filter
access-list 1 permit xxxxxxxxxxxxxx
access-list 2 permit xxxxxxxxxxxxxx
gaurav@localhost:~/unix$ perl -wln -e 'print $1 if /.*\sextended\s(.*)\s?.*$/' test2.txt 
BLA_Outgoing_Filter
gaurav@localhost:~/unix$ perl -wln -e 'print $1 if /.*\s1\s(.*)\s?.*$/' test2.txt 
permit xxxxxxxxxxxxxx
permit xxxxxxxxxxxxxx
gaurav@localhost:~/unix$

Regards,
Gaurav.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find a word in a file, and change a word beneath it ??

Hi all, I have a file with lines written somewhat like this. aaaa ccc aa linux browse = no xssxw cdcedc dcsdcd csdw police dwed dwd browse = no cdecec (2 Replies)
Discussion started by: vikas027
2 Replies

2. Shell Programming and Scripting

Replace only if the keyword is the first word in every line

How do I replace only if the keyword is at the begining of a line? Code: -- a = “This is a print statement” print a -- What if I want to replace print by #print only in the second line i.e only if the line starts with that keyword. Please help me out. I'm new to SED. -----Post... (5 Replies)
Discussion started by: alexzubin
5 Replies

3. Shell Programming and Scripting

find keyword from file and search in another file

hi dudes; this is my file.txt:20101228-180436_Down a 1 b 2 ... 20101228-190436_Rollback a 1 40 e 3 20 ... 20101228-180436_Down c 2 f 2 c 1 ... and i have a down.txt:a 1 aa 2 30 bb 1 40 b 2 ab 3 10 c 3 cd 4 50 ac 2 20 c 3 ad 1 0 (2 Replies)
Discussion started by: gc_sw
2 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Shell Programming and Scripting

How to get the next word which falls just after a keyword?

Hi friends, i just want to know the command though which i can get the next word which comes just after a particluar keyword. For example: suppose text.out is file which contains a pl/sql procedure . i want to find out the word which falls just after the "table1" keyword. Thank... (7 Replies)
Discussion started by: neelmani
7 Replies

6. Shell Programming and Scripting

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it?

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it. for example there is a file a.txt. $more a.txt create view as (select from ......... .......... ( select .... ( select ...... .. select only no ((( number ( select end (12 Replies)
Discussion started by: neelmani
12 Replies

7. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies

8. Shell Programming and Scripting

Need to extract the word after a particular keyword throughout the file..

Hi Everyone, Need help in extracting the hostname from the below output. Expected output: DS-TESTB-GDS-1.TEST.ABC.COM DS-TESTB-GDS-2.TEST.ABC.COM .... ... /tmp $ cat -n /tmp/patchreport 1 /usr/bin/perl /admin/bin/patch/applyPatches.pl --apply_patches... (4 Replies)
Discussion started by: thiyagoo
4 Replies

9. Shell Programming and Scripting

Find all lines in file such that each word on that line appears in at least n lines of the file

I have a file where every line includes four expressions with a caret in the middle (plus some other "words" or fields, always separated by spaces). I would like to extract from this file, all those lines such that each of the four expressions containing a caret appears in at least four different... (9 Replies)
Discussion started by: uncleMonty
9 Replies

10. UNIX for Beginners Questions & Answers

How to align/sort the column pairs of an csv file, based on keyword word specified in another file?

I have a csv file as shown below, xop_thy 80 avr_njk 50 str_nyu 60 avr_irt 70 str_nhj 60 avr_ngt 50 str_tgt 80 xop_nmg 50 xop_nth 40 cyv_gty 40 cop_thl 40 vir_tyk 80 vir_plo 20 vir_thk 40 ijk_yuc 70 cop_thy 70 ijk_yuc 80 irt_hgt 80 I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies
RAPOLICY(1)						      General Commands Manual						       RAPOLICY(1)

NAME
rapolicy - compare a argus(8) data file/stream against a Cisco Access Control List. COPYRIGHT
Copyright (c) 2000-2003 QoSient. All rights reserved. SYNOPSIS
rapolicy -r argus-file [ra options] DESCRIPTION
Rapolicy reads argus data from an argus-file list, and tests the argus data stream against a Cisco access control list configuration file, printing out records that represent activity that would violate the policy. Rapolicy can be used to indicate access control violations, as well as test new access control definitions prior to installing them in a router. OPTIONS
Rapolicy, like all ra based clients, supports a large number of options. Options that have specific meaning to rapolicy are: -f <Cisco ACL file> Print records that violate the policy. -D 0 (default) Print records that violate the policy. -D 1 Print records and the violated ruleset. -D 2 Print all records and the ruleset that matched. See ra(1) for a complete description of ra options. EXAMPLE INVOCATION
rapolicy -r argus.file CISCO ACL SYNTAX
There does not seem to be authoritative Cisco-ACL-Documentation, nor ACL syntax standardization. Because Cisco has been know to improve its ACL rules syntax, rapolicy is known to work with Cisco ACL router defintions up to July, 2002. A Cisco ACL configuration file consists of a collection of any number of ACL statements, each on a separte line. The syntax of an ACL statement is: ACL = "access-list" ID ACTION PROTOCOL SRC DST NOTIFICATION ID = Number ACTION = permit | deny PROTO = protocol name | protocol number SRC | DST = ADDRESS [PORTMATCH] ADDRESS = any | host HOSTADDR | HOSTADDR HOSTMASK HOSTADDR = ipV4 address HOSTMASK = matching-mask PORTMATCH = PORTOP PORTNUM | range PORTRANGE PORTOP = eq | lt | gt | neq | established PORTRANGE = PORTNUM PORTNUM PORTNUM = TCP or UDP port value (unsigned decimal from 0 to 65535) EXAMPLE CONFIGURATION
This example Cisco Access Control List configuration is provided as an example only. No effort has been made to verify that this example Access Control List enforces a useful access control policy of any kind. #allow www-traffic to webserver access-list 102 permit tcp any 193.174.13.99 0.0.0.0 eq 80 #allow ftp control connection to server access-list 102 permit tcp any 193.174.13.99 0.0.0.0 eq 21 #allow normal ftp access-list 102 permit tcp any 193.174.13.99 0.0.0.0 eq 20 #allow ftp passive conncetions in portrange 10000 to 10500 access-list 102 permit tcp any host 193.174.13.99 range 10000 10500 #dummy example access-list 102 permit tcp host 193.174.13.1 eq 12345 host 193.174.13.2 range 12345 23456 #deny the rest access-list 102 deny tcp any any #same thing in other words: access-list 102 deny tcp 0.0.0.0 255.255.255.255 0.0.0.0 255.255.255.255 AUTHORS
Carter Bullard (carter@qosient.com). Olaf Gellert (gellert@pca.dfn.de). SEE ALSO
ra(1), rarc(5), argus(8) 22 July 2002 RAPOLICY(1)
All times are GMT -4. The time now is 07:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy