Mombu the GNU Linux Forum sponsored links

Go Back   Mombu the GNU Linux Forum > GNU_Linux > text replace
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st April 08:42
matt
External User
 
Posts: 1
Default text replace



Not sure if this is the right group, but I am looking for a text replacement
command that is able to convert an ip address into a hyperlink.

For example:
I have the following in my file:

Feb 1 12:37: 192.168.1.2 : WARN-Updown Interface FastEthernet0/38, changed
state to down
Feb 1 12:37: 192.168.1.4 : WARN-Updown Line Protocol on Interface
FastEthernet0/12, changed state to down


I want to output this:

Feb 1 12:37: <a href="telnet://192.168.1.2">192.168.1.2</a> : WARN-Updown
Interface FastEthernet0/38, changed state to down
Feb 1 12:37: <a href=telnet://192.168.1.4>192.168.1.4</a> : WARN-Updown Line
Protocol on Interface FastEthernet0/12, changed state to down

But I'm not sure how to get the 192.168.1.x to the form of <a
href="telnet://192.168.1.x">192.168.1.x</a>

I've searched through sed do***entation, and don't see any way to make this
work. I'm not sure if sed is the way to go. Any help would be appreciated.

Thanks,
Matt
  Reply With Quote


  sponsored links


2 21st April 08:42
tommy reynolds
External User
 
Posts: 1
Default text replace



Sed to the rescue!

---- cut ---- cut ---- cut ---- cut ---- cut ---- cut ---- cut ---- #!/bin/sh
sed -re 's;([0-9][0-9]?[0-9]?[.][0-9][0-9]?[0-9]?[.][0-9][0-9]?[0-9]?[.][0-9][0-9]?[0-9]?);<a href=telnet://\1">\1</a>;g' $@
---- cut ---- cut ---- cut ---- cut ---- cut ---- cut ---- cut ----

and run it either as a filter or with the input file on the command
line.

Cheers!
  Reply With Quote
3 21st April 08:42
paul
External User
 
Posts: 1
Default text replace


You could look at awk - awk '{FS=" "}{print $1 " " $2 " " $3 " \<a
href=\"telnet:\/\/" $4 "Other fixed text}'

You might have to fiddle with the "\"s and also the input from whatever
file the input is in ( awk ... < inFile > >outFile )

sed is a little messier I think but will work ( I try and avoid complex
REs - just a personal thing )
  Reply With Quote
4 21st April 08:43
matt
External User
 
Posts: 1
Default text replace


That's perfect. Thanks for your help.
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666