The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Korn Shell script not running Asty Shell Programming and Scripting 1 08-11-2006 10:17 AM
Help with Korn Shell script heprox AIX 1 12-19-2005 11:04 AM
korn shell script pavan_test UNIX Desktop for Dummies Questions & Answers 3 10-27-2005 09:09 AM
korn shell script pavan_test UNIX for Dummies Questions & Answers 1 10-26-2005 10:17 AM
shell script : text manipulation (easy quesiton) champion Shell Programming and Scripting 3 07-01-2002 12:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-22-2008
Registered User
 

Join Date: Aug 2006
Posts: 9
Pattern manipulation in korn shell script using sed.

Hi,

Could any one let me know, how can I cut the last field in below mentioned line.

net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.37.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.1.0,10.253.0.1 net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.38.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.2.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.39.0,10.253.0.1
net,-hopcount,0,,0,10.14.185.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,0,10.14.185.1
net,-hopcount,0,-netmask,255.255.0.0,,,,,10.253.0.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.9.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.36.0,10.253.0.1

I want to get all the gate way mentioned in bold above., ie last 10.253.0.1. we can't use the filed separator as " , " while using awk as the number of parameter varies. Tried all awk but hope can do it using sed. would like to know the format.

Thanks,
Ajilesh
Reply With Quote
Forum Sponsor
  #2  
Old 08-22-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,196
With awk you can get the last field with $NF:

Code:
awk -F, '{print $NF}' file
Regards
Reply With Quote
  #3  
Old 08-22-2008
Registered User
 

Join Date: Aug 2008
Posts: 81
Try this..

$ awk -F"," '{ print $NF }' <<File name >>
Reply With Quote
  #4  
Old 08-22-2008
Registered User
 

Join Date: Aug 2006
Posts: 9
It works...!! Great..!!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0