General Discussion > Computer Usage and Setup Help
[shell] Get last part of a string ?
(1/1)
Hayleia:
First of all, what does "last part" mean ? It means "all characters after some special character". For example, if that character is "-", then the "last part" of "1574-114687-415" is "415" and the "last part" of "jg7e;f,k-e" is "e".
So, yeah, how do I extract the "last part" of a string (you can provide examples with the "-") ?
edit that's surely not informative, but I am using Ubuntu 13.04
SpiroH:
Question: Is this supposed to be solved using shell scripts only?
Hooloovoo:
I did this using sed, a stream editor.
--- Code: ---echo "1574-114687-415" | sed s/.*-//
--- End code ---
will replace everything at the beginning of a string that has a - at the end with nothing, and continue on in this way. It returns everything which doesn't have a - after it.
Hayleia:
--- Quote from: SpiroH on December 07, 2013, 01:14:19 pm ---Question: Is this supposed to be solved using shell scripts only?
--- End quote ---
Yes.
--- Quote from: fortytwo on December 07, 2013, 01:24:42 pm ---I did this using sed, a stream editor.
--- Code: ---echo "1574-114687-415" | sed s/.*-//
--- End code ---
will replace everything at the beginning of a string that has a - at the end with nothing, and continue on in this way. It returns everything which doesn't have a - after it.
--- End quote ---
Thanks, that works great :D
Navigation
[0] Message Index
Go to full version