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
count times for one string anhtt Shell Programming and Scripting 1 03-04-2008 10:46 AM
count string occurance in a file hourly ayhanne UNIX for Dummies Questions & Answers 2 10-13-2007 07:47 AM
Count string at header. Helmi Shell Programming and Scripting 13 04-25-2007 04:16 AM
How to count the string length Anshu UNIX for Dummies Questions & Answers 2 06-15-2006 12:32 AM
Word Count without any characters but the Output String JP_II UNIX for Dummies Questions & Answers 3 06-07-2006 05:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-05-2005
Registered User
 

Join Date: May 2005
Posts: 2
count from right end of string

hi all,
I'm trying to use substr(p,c,l) in awk but i'd like to have the 'position' argument count from the right end of the string instead of left end.
evidently, just putting a '-' sign in front of the number does not work. any ideas?
cheers,
kl
Reply With Quote
Forum Sponsor
  #2  
Old 05-05-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Try something like
nawk '{print(substr($0,length($0)-4,1))}' myfile
Which'll print the fifth character from the right hand side of each record (assume position is zero-indexed).

Cheers
ZB
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:13 AM.


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