Very simple awk for a simple user 
Author Message
 Very simple awk for a simple user

Hi,

how would I awk this:

ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54

to this:

207.230.225.229

yes, this is trivial, but I am new to awk

Thanks

Luis Zuniga



Mon, 23 Aug 2004 07:55:10 GMT  
 Very simple awk for a simple user

Quote:
> Hi,

> how would I awk this:

> ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54

> to this:

> 207.230.225.229

> yes, this is trivial, but I am new to awk

> Thanks

> Luis Zuniga


one! line

echo "ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 =
54" | awk 'BEGIN{FS=OFS="."}{sub(" = [0-9]*","");print $5,$6,$7,$8}'

Would be one out of numerous possible ways to solve this.

Michael Heiming
--
Remove the +SIGNS case mail bounces.



Mon, 23 Aug 2004 09:43:36 GMT  
 Very simple awk for a simple user
Another solution, using regular expressions is:

echo "ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54" |\
awk '{sub(/([^.]*\.){4}/,"",$1);print $1}'

Quote:

> Hi,

> how would I awk this:

> ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54

> to this:

> 207.230.225.229

> yes, this is trivial, but I am new to awk

> Thanks

> Luis Zuniga




Mon, 23 Aug 2004 23:00:42 GMT  
 Very simple awk for a simple user

Quote:


>> Hi,

>> how would I awk this:

>> ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54

>> to this:

>> 207.230.225.229

>> yes, this is trivial, but I am new to awk
> Another solution, using regular expressions is:

> echo "ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54" |\
> awk '{sub(/([^.]*\.){4}/,"",$1);print $1}'

Or:
    echo "ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54" |
        awk -F '[. ]' '{print $5"."$6"."$7"."$8}'

    SunOS/Solaris, use nawk.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright _YEAR_, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



Tue, 24 Aug 2004 06:30:24 GMT  
 Very simple awk for a simple user
I am a fan of regular expressions...  this has the advantage that if
the text IP address has an unspecified number of words, it will still
work (ie:

this.one.works.10.10.10.10 = 10
so.does.this.one.as.well.you.gomer.20.20.20.20 = 20
okay.30.30.30.30 = 30

The command is:

sed 's/[^0-9]*\([0-9][0-9\.]*[0-9]\).*/\1/'

The disadvantage is if the text has numbers, it will bomb out and
print only the first set of numbers.  In this case you need a little
more confusion:

For example (note the 66)
ip.ipAddrTable.ipAd66Entry.ipAdEntIfIndex.207.230.225.229 = 54

sed 's/.*\.\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/'

Quote:

> Hi,

> how would I awk this:

> ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.207.230.225.229 = 54

> to this:

> 207.230.225.229

> yes, this is trivial, but I am new to awk

> Thanks

> Luis Zuniga




Fri, 27 Aug 2004 04:00:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. developing in J with simple tools and simple minds

2. Simple courses in J for simple (ordinary) people

3. Simple courses in J for simple (ordinary) people

4. Simple courses in J for simple (ordinary) people

5. Simple task-not simple for Dummy, Help

6. Simple Hardware, Simpler FORTH

7. Simple forth question - maybe simple ?

8. Question in french (a simple question, very simple)

9. Simple Question seeks simple answer

10. Simple problem, simple solution.

11. Simple awk question

12. A very simple question on SED or AWK for a GURU, and an enjoyable problem

 

 
Powered by phpBB® Forum Software