Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Right() 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello again awk fans,

In a string that is say 10 characters in length, how can I retrieve the right 3 most characters?

I am trying to emulate a right(string,n) function found in many languages.





Thanks,

Michael42
 
A starting point:
echo "1234567890\nabcdefghij" | awk '{print substr($0,1+length($0)-3)}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Once again - that was perfect. :) I was close but being new to awk I did not quite have the syntax correct.

Thanks again for posting,

Michael42

Thanks,

Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top