Use awk to change an IP format | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Use awk to change an IP format

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-08-2013
MrEddy MrEddy is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 9 January 2014, 2:27 PM EST
Posts: 46
Thanks: 3
Thanked 0 Times in 0 Posts
Use awk to change an IP format

Basically I am trying to run a standard output of IP address with a port number into another command but I need to change it from.

74.125.224.194.80 into 74.125.224.194:80

One command wants a period before the port the subsequent one wants a colon.

So is there anyway I can feed 74.125.224.194.80 into awk and have it just substitute a : in for the 4th period it finds?

I can find all kinds of ways to do global substitutions but I don't need all periods to have a : just the last one.

Thanks in advance!
Sponsored Links
    #2  
Old 02-08-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 21 October 2014, 7:53 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts

Code:
echo 74.125.224.194.80 | awk -F"." 'NF==5{v=$NF;sub(/\.[0-9]+$/,":"v)}1'

The Following User Says Thank You to Yoda For This Useful Post:
MrEddy (02-08-2013)
Sponsored Links
    #3  
Old 02-08-2013
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
It would be easier to use sed:

Code:
sed 's/\./:/4'

Regards,
Alister
The Following User Says Thank You to alister For This Useful Post:
MrEddy (02-08-2013)
    #4  
Old 02-08-2013
MrEddy MrEddy is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 9 January 2014, 2:27 PM EST
Posts: 46
Thanks: 3
Thanked 0 Times in 0 Posts
Awesomeness thanks! works like a charm
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - change date format vegasluxor Shell Programming and Scripting 8 01-25-2013 05:32 AM
Change a file content format using awk fastlane3000 Shell Programming and Scripting 3 01-25-2013 01:43 AM
using awk or bash to change the format yanglei_fage Shell Programming and Scripting 3 07-13-2012 10:54 PM
How can I change is output format by awk ? wanchem Shell Programming and Scripting 8 05-08-2010 06:46 AM
awk,cut fields by change field format jimmy_y Shell Programming and Scripting 7 11-05-2009 12:49 PM



All times are GMT -4. The time now is 07:56 PM.