We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,039 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

bash string manipulation

echo ${NUM:0:2}

The above is just an example of the kind of code I'M using. I need a way to represent the end of the string. Is there a way to start from the right side of a line of text instead of the left? What I'M trying to do here is grab the last three digits on end, then the next three and so on. NUM in this case will be a user input so there is no way to hard code the end position. Thanks.

3
Contributors
2
Replies
3 Weeks
Discussion Span
3 Months Ago
Last Updated
5
Views
Question
Answered
Garrett85
Posting Pro in Training
426 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Self-Answered as of 4 Months Ago

I'm not sure this is what you are asking for but I like to answer part of your question.

Is there a way to start from the right side of a line of text instead of the left? What I'M trying to do here is grab the last three digits on end, then the next three and so on

ravikumar@suselinux:~> echo "123456789" |rev |fold -w 3 |rev
789
456
123
ravi89
Junior Poster
117 posts since Jun 2009
Reputation Points: 11
Solved Threads: 14
Skill Endorsements: 0
string=123456789
echo ${string: -3}
789
Watael
Junior Poster
121 posts since Apr 2012
Reputation Points: 4
Solved Threads: 26
Skill Endorsements: 2

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0600 seconds using 2.66MB