|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using printf in bash
Code:
printf "%5.5\n" "1234567890" will print 12345 . How do I get it to print 67890 Essentially, I just want the last 5 characters rather than the first 5. Last edited by Scrutinizer; 01-04-2013 at 06:19 AM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Substring Extraction
Code:
num="1234567890"
printf "%d\n" ${num: -5} |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
This works for numbers. Use
%s format specifier for characters: Code:
$ var="ABCDEFGHIJK"
$ printf "%5s\n" ${var:5}
FGHIJK
or
$ printf "%5s\n" ${var: -3}
IJK |
|
#4
|
|||
|
|||
|
Thanks!
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Code:
num="1234567890"
echo "${num#?????}" |
| Sponsored Links | ||
|
![]() |
| Tags |
| bash, printf |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| printf error: "not enough parameters in printf statement" | Leedor | Shell Programming and Scripting | 2 | 09-28-2010 09:33 AM |
| floating point not recognized by printf in bash | josegr | Shell Programming and Scripting | 2 | 03-06-2010 11:36 PM |
| [bash]printf octal instead of decimal | dolphin06 | Shell Programming and Scripting | 3 | 04-14-2009 06:38 AM |
| printf in bash shell not printing negative values | npatwardhan | Shell Programming and Scripting | 2 | 01-14-2009 04:51 PM |
| printf | arunviswanath | Programming | 2 | 09-19-2007 09:31 PM |
|
|