sed OR-Operation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed OR-Operation
# 1  
Old 06-02-2010
sed OR-Operation

Hello,

I'm trying to get the configuration-IP-Addresses from Cisco-configurations

on the Routers they are defined as a Loopback0-interface like this:
Code:
interface Loopback0
ip address 172.23.19.249 255.255.255.255

On the Switches they are defined as a VLAN 80 interface like this
Code:
interface Vlan80
 ip address 172.23.19.177 255.255.255.240

I can get out the IP-Address of the routers using this:
Code:
for i in `ls newestconfigs/ | grep confg`
do 
  echo `cat newestconfigs/$i \
      | awk '/^hostname/ {print $2}'`\
        ": " \
        `cat newestconfigs/$i \
          | sed -n '/^interface.Loopback0/ ,+1p' \
          | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' \
          | head -1`
done

Is there a possibility to add the an OR-Operation to the sed-command to scan for "interface Loopback0" OR for "interface Vlan80" and print out the one that first occurs?

Thanks for your help.

Love, Sally

P.S. I'm trying to get familiar with regular expressions since 10 years, this time it seems to work... Smilie
# 2  
Old 06-02-2010
Hi,

try

Code:
sed -n "/interface Loopback0\|Vlan80/p;q" data

to search for either "interface Loopback0" oder "interface Vlan80" and quit after the first hit.

HTH Chris
# 3  
Old 06-02-2010
Hello Chris,

this works, when I do not add the "q". Normally this should be ok, but I have to try how it responds on a device that have both, Loopback0 and Vlan80, eg. Layer-3-Switches.

Thanks, Sally
# 4  
Old 06-02-2010
Another way:
Code:
for i in `ls newestconfigs/ | grep confg`
do
  awk '
      /^hostname/ { host=$2 ; next }
      /^interface (Loopback0|Vlan80)/ { getIp=1 ; next }
      getIp { print host ": " $2 ; exit }

  ' newestconfigs/$i
done

Jean-Pierre.

Last edited by aigles; 06-02-2010 at 08:20 AM..
This User Gave Thanks to aigles For This Post:
# 5  
Old 06-02-2010
this is a really nice solution... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple Replacement in a Text File in one operation (sed/awk) ?

Hi all, Saying we have two files: 1. A "Reference File" whose content is "Variable Name": "Variable Value" 2. A "Model File" whose content is a model program in which I want to substitute "VariableName" with their respective value to produce a third file "Program File" which would be a... (4 Replies)
Discussion started by: dae
4 Replies

2. Shell Programming and Scripting

Complex string operation (awk, sed, other?)

I have a file that contains RewriteRules for 200 countries (2 examples for 1 country below): RewriteRule ^/at(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=de_AT #& RewriteRule ^/at_english(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=en_AT I have... (5 Replies)
Discussion started by: usshadowop
5 Replies

3. Shell Programming and Scripting

sed command to skip the first line during find and replace operation

Hi Gurus, I did an exhaustive search for finding the script using "sed" to exclude the first line of file during find and replace. The first line in my file is the header names. Thanks for your help.. (4 Replies)
Discussion started by: ks_reddy
4 Replies

4. Shell Programming and Scripting

Sed emptying file when i use for search replace operation

Hi Friends I am new to sed programming , i found that the below code can search for the $ToSearch and Replace it with $ToReplace ( $ToSearch and $ToReplace are my variables in my script ) sed "s/$ToSearch/$ToReplace/" $file > $output mv $output $file In testing the script i found that... (3 Replies)
Discussion started by: rakeshkumar
3 Replies

5. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

6. Solaris

Operation and Maintenance

I gurus of Solaris, I need to do a Procedure concerning in the Maintenance of Solaris Server. What are the parameters that I must be see Periodically in a Server. For example the space I (df -h) must be each week.- In this server exist a Database aplication (Oracle), and log's that increase or... (4 Replies)
Discussion started by: andresguillen
4 Replies

7. Shell Programming and Scripting

String Operation

/home8/mc09ats/UnixCw/file4 this is the path...i have 2 variables filename and filepath...i want filename=file4 filepath=/home8/mc09ats/UnixCw i.e. i think i have to find last occurence of "/" in string and the string after "/" want to take in some variable and string before last "/"... (4 Replies)
Discussion started by: AbhijitIT
4 Replies

8. Shell Programming and Scripting

File Operation

I have one text file like 1 filename 2 filename2 3 hi 4 myname i have one variable in which i have index value..i.e.1,2,3 and so... i want to copy value after the index into somevariable..... how i can do it.... (2 Replies)
Discussion started by: AbhijitIT
2 Replies

9. Shell Programming and Scripting

sed command for substring operation

Hi All, Input=abcDEF_1.6k1 I need to use ‘sed' command to get 1.6 value and store to some variable from the given input. Please help me in getting the command. Regards, Kalai (2 Replies)
Discussion started by: kalpeer
2 Replies

10. Shell Programming and Scripting

string operation

i am new user of unix.i have a question.My script is- export STR_ALFA=`head -2 "${FILE_PATH}"|tail -1|cut -d"," -f1` "${TEST_HOME}"/function/chk_alfa.ksh STR_ALFA now i want to check STR_ALFA: 1)whether is alphabetic 2)whether is numeric 3)whether is alphanumeric... (1 Reply)
Discussion started by: arghya_owen
1 Replies
Login or Register to Ask a Question