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. |
Code:
NUM=123456789 |
Thanks, one more thing
Thanks. Now I need help on the following.
OLDSTRING=$(( ${NUM}-${NEWSTRING} )) # I need to set OLSTRING to NUM - NEWSTRING My syntax is all wrong here if someone could give me a hand. Thanks. Quote:
|
Quote:
|
Not sure if I understand, but
Code:
echo ${NUM: 0: -$DIGITS} |
the problem
Nevermind I got it.
NEWSTRING=${NUM: -$DIGITS} OLDSTRING=${NUM:0:${NEWSTRING}} Okay, now I see that it is working but with unintended results. I was hoping to set OLDSTRING minues the digits in new string but instead I'M getting OLDSTING - 1. If I were to input 1000 I would want NEWSTRING to hold 000 and old string to hold everything that is left over to the left, in this case, 1. Any ideas? Code:
for n in ${PROCESSGROUPS}; Quote:
|
[QUOTE=Garrett85;4864801]
Quote:
Code: Code:
num=1234 Code:
num= 1234 |
Quote:
Code:
NEWSTRING=${NUM:(-3)} |
All times are GMT -5. The time now is 11:28 PM. |