Solved

Regex question & awk

Posted on 2013-12-17
11
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ubuntu Apache Webserver - File Permissions 5 77
How to identify a paragraph in the body of text? 2 55
Linux 3 37
check the file dates in unix 14 30
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

726 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