Solved

Regex question & awk

Posted on 2013-12-17
11
236 Views
Last Modified: 2013-12-17
How should i export bold parts from the given text below

IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.159.252 = STRING: 0:25:90:a8:9a:ef

and there is one additional thing if it has one char between two double dot  as this

IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.158.25 = STRING: 0:4:ac:e3:e8:49

it will export 00:04:ac:e3:e8:49 i mean it will add a 0 to infront of alone char between dots


IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.159.252 = STRING: 0:25:90:a8:9a:ef
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.159.253 = STRING: 0:25:90:a8:9a:ef
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.159.254 = STRING: 0:50:56:be:f1:5f
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.192.168.1.104 = STRING: 2:d0:68:12:4b:cc

Open in new window

0
Comment
Question by:3XLcom
  • 6
  • 5
11 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 39724487
So from this text,
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.159.252 = STRING: 0:25:90:a8:9a:ef

You want to extract IP address and MAC, this is all what I see is bolded?


Something like?

echo 'IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.185.9.159.252 = STRING: 0:25:90:a8:9a:ef' | sed 's/.*ipv4\.\([0-9\.]*\).*=.*STRING: \(.*\)/\1 \2/'

Open in new window

0
 

Author Comment

by:3XLcom
ID: 39724522
i need to export this from a text file
0
 
LVL 31

Expert Comment

by:farzanj
ID: 39724539
Export??  Adding 0 in front?  Also for IP?  Export where?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:3XLcom
ID: 39724592
my server generates tooo long text files as this and i want to export a result as :


172.16.1.21  ->  0:18:6e:37:cf:28
172.16.1.22  ->  00:01:e8:d6:53:37

but one important point on the text 00:01:e8:d6:53:37 that seems as 0:1:e8:d6:53:37 if it has one decimal between two dots it will add one more zero to infront of it



IP-MIB::ipNetToPhysicalPhysAddress.1107755015.ipv4.172.16.1.21 = STRING: 0:18:6e:37:cf:28
IP-MIB::ipNetToPhysicalPhysAddress.1107755015.ipv4.172.16.1.22 = STRING: 0:1:e8:d6:53:37
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.10.1.1.1 = STRING: 0:1:e8:d6:53:37
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.3 = STRING: 0:50:56:be:70:d8
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.5 = STRING: 0:4:ac:e3:e8:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.6 = STRING: 0:4:ac:e3:e8:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.9 = STRING: 2:d0:68:12:4b:cc
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.18 = STRING: 90:2b:34:9d:53:cb
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.19 = STRING: 90:2b:34:9d:53:cb
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.20 = STRING: 90:2b:34:a0:42:f3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.21 = STRING: 90:2b:34:a0:42:f3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.34 = STRING: e0:69:95:2e:90:a4
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.35 = STRING: e0:69:95:2e:90:a4
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.36 = STRING: 90:2b:34:a0:42:f3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.39 = STRING: e0:69:95:2e:90:a4
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.67 = STRING: b8:ac:6f:97:82:6f
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.116 = STRING: 0:4:ac:e3:e8:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.162 = STRING: 0:50:56:be:36:c1
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.178 = STRING: 0:50:56:96:50:fa
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.179 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.180 = STRING: 0:50:56:96:3:c3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.181 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.182 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.183 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.184 = STRING: 0:50:56:96:3:c3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.185 = STRING: 0:50:56:96:25:99
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.188 = STRING: 0:50:56:96:3:c3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.189 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.226 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.227 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.228 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.229 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.230 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.231 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.232 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.233 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.234 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.235 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.236 = STRING: 0:50:56:be:d0:49

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
ID: 39724864
Ok, export word is still confusing.

Try this command:

perl -ne 'if(($a,$b)=m{ipv4\.(\S+)\s=\sSTRING:\s(\S+)}) { $b =~ s/\b(\d)\b/0$1/g; print "$a --> $b\n";} logfilename'

Open in new window


change logfilename to the filename of your log file.

See what you get.  If you are happy with the output, you can redirect it to any file.
0
 

Author Comment

by:3XLcom
ID: 39724879
This is the result :

[root@sflow islemler]# perl -ne 'if(($a,$b)=m{ipv4\.(\S+)\s=\sSTRING:\s(\S+)}) { $b =~ s/\b(\d)\b/0$1/g; print "$a --> $b\n";} snmplogs/router.txt'

Illegal division by zero at -e line 1, <> line 1.

Open in new window



And txt file :

IP-MIB::ipNetToPhysicalPhysAddress.1107755015.ipv4.172.16.1.21 = STRING: 0:18:6e:37:cf:28
IP-MIB::ipNetToPhysicalPhysAddress.1107755015.ipv4.172.16.1.22 = STRING: 0:1:e8:d6:53:37
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.10.1.1.1 = STRING: 0:1:e8:d6:53:37
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.3 = STRING: 0:50:56:be:70:d8
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.5 = STRING: 0:4:ac:e3:e8:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.6 = STRING: 0:4:ac:e3:e8:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.9 = STRING: 2:d0:68:12:4b:cc
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.18 = STRING: 90:2b:34:9d:53:cb
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.19 = STRING: 90:2b:34:9d:53:cb
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.20 = STRING: 90:2b:34:a0:42:f3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.21 = STRING: 90:2b:34:a0:42:f3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.34 = STRING: e0:69:95:2e:90:a4
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.35 = STRING: e0:69:95:2e:90:a4
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.36 = STRING: 90:2b:34:a0:42:f3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.39 = STRING: e0:69:95:2e:90:a4
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.67 = STRING: b8:ac:6f:97:82:6f
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.116 = STRING: 0:4:ac:e3:e8:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.162 = STRING: 0:50:56:be:36:c1
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.178 = STRING: 0:50:56:96:50:fa
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.179 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.180 = STRING: 0:50:56:96:3:c3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.181 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.182 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.183 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.184 = STRING: 0:50:56:96:3:c3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.185 = STRING: 0:50:56:96:25:99
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.188 = STRING: 0:50:56:96:3:c3
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.189 = STRING: 0:50:56:96:3:8b
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.226 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.227 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.228 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.229 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.230 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.231 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.232 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.233 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.234 = STRING: 0:50:56:be:d0:49
IP-MIB::ipNetToPhysicalPhysAddress.1107787875.ipv4.37.123.96.235 = STRING: 0:50:56:be:d0:49

Open in new window

0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 39724901
Ok, try:

perl -ne 'if(($a,$b)=m{ipv4\.(\S+)\s=\sSTRING:\s(\S+)}) { $b =~ s/\b(\d)\b/0$1/g; print "$a --> $b\n";}' snmplogs/router.txt

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
ID: 39724915
perl -ne 'if(($a,$b)=m{ipv4\.(\S+)\s=\sSTRING:\s(\S+)}) { $b =~ s/\b(\d)\b/0$1/g; print "$a --> $b\n";}' file

Open in new window


This is what I get:

172.16.1.21 --> 00:18:6e:37:cf:28
172.16.1.22 --> 00:01:e8:d6:53:37
10.1.1.1 --> 00:01:e8:d6:53:37
37.123.96.3 --> 00:50:56:be:70:d8
37.123.96.5 --> 00:04:ac:e3:e8:49
37.123.96.6 --> 00:04:ac:e3:e8:49
37.123.96.9 --> 02:d0:68:12:4b:cc
37.123.96.18 --> 90:2b:34:9d:53:cb
37.123.96.19 --> 90:2b:34:9d:53:cb
37.123.96.20 --> 90:2b:34:a0:42:f3
37.123.96.21 --> 90:2b:34:a0:42:f3
37.123.96.34 --> e0:69:95:2e:90:a4
37.123.96.35 --> e0:69:95:2e:90:a4
37.123.96.36 --> 90:2b:34:a0:42:f3
37.123.96.39 --> e0:69:95:2e:90:a4
37.123.96.67 --> b8:ac:6f:97:82:6f
37.123.96.116 --> 00:04:ac:e3:e8:49
37.123.96.162 --> 00:50:56:be:36:c1
37.123.96.178 --> 00:50:56:96:50:fa
37.123.96.179 --> 00:50:56:96:03:8b
37.123.96.180 --> 00:50:56:96:03:c3
37.123.96.181 --> 00:50:56:96:03:8b
37.123.96.182 --> 00:50:56:96:03:8b
37.123.96.183 --> 00:50:56:96:03:8b
37.123.96.184 --> 00:50:56:96:03:c3
37.123.96.185 --> 00:50:56:96:25:99
37.123.96.188 --> 00:50:56:96:03:c3
37.123.96.189 --> 00:50:56:96:03:8b
37.123.96.226 --> 00:50:56:be:d0:49
37.123.96.227 --> 00:50:56:be:d0:49
37.123.96.228 --> 00:50:56:be:d0:49
37.123.96.229 --> 00:50:56:be:d0:49
37.123.96.230 --> 00:50:56:be:d0:49
37.123.96.231 --> 00:50:56:be:d0:49
37.123.96.232 --> 00:50:56:be:d0:49
37.123.96.233 --> 00:50:56:be:d0:49
37.123.96.234 --> 00:50:56:be:d0:49
37.123.96.235 --> 00:50:56:be:d0:49

Open in new window

0
 

Author Closing Comment

by:3XLcom
ID: 39724918
That is it thanks .
0ne last question is there any wat the make all chars upper case
0
 
LVL 31

Expert Comment

by:farzanj
ID: 39724940
Welcome.

Try this:
perl -ne 'if(($a,$b)=m{ipv4\.(\S+)\s=\sSTRING:\s(\S+)}) { $b =~ s/\b(\d)\b/0$1/g; print "$a --> ".uc($b)."\n";}' file

Open in new window

0
 

Author Comment

by:3XLcom
ID: 39724949
perfect thnx
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS - HAProxy- KeepAlived 5 51
reset ubuntu password for root and admin after clearing it. 7 56
Regular expression help 2 34
Apache LDAP Authentication 20 23
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question