maverickxx
asked on
need last three characters of the string
I need last three chaarcters of string . I have series of of file names
somefilename1.xyz112
somefilename2.abc121
...
I need to get last three characters(112 or 121 or 131 etc which are version numbers which I reuse later)
thanks in advance
somefilename1.xyz112
somefilename2.abc121
...
I need to get last three characters(112 or 121 or 131 etc which are version numbers which I reuse later)
thanks in advance
ASKER
HRL ,
perhaps I should have been clear
unix shell scripting bash
perhaps I should have been clear
unix shell scripting bash
Assuming you have this list in sample.text...
sed 's/.*\(...\)$/\1/' sample.txt
ASKER
mgh-mgharish
can I do something like this
version = $file_name | sed 's/\(.*\).../\1/'
then use version in some other
where $file_name is various file names
can I do something like this
version = $file_name | sed 's/\(.*\).../\1/'
then use version in some other
where $file_name is various file names
Try this:
export version=`echo $file_name | sed 's/\(.*\)...$/\1/'`
echo $version
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mgh_mgharish
thanks that worked
thanks that worked
#!/bin/bash
string=somefilename1.xyz11 2
echo ${string: -3}
string=somefilename1.xyz11
echo ${string: -3}
ozo, will that work if string has multiple lines?
string='somefilename1.xyz1 12
somefilename2.abc121'
echo ${string: -3}
somefilename2.abc121'
echo ${string: -3}
That gives only 121, not 112
112 are not the last three characters of the string
:-)
Just wanted to know if that was possible.. The question requested for last three characters for each line..
Just wanted to know if that was possible.. The question requested for last three characters for each line..
I thought it was
"need last three characters of the string"
"need last three characters of the string"
file_name='somefilename1.x yz112
somefilename2.abc121'
export version=`echo $file_name | sed 's/.*\(...\)$/\1/'`
echo $version
also gives only 121
somefilename2.abc121'
export version=`echo $file_name | sed 's/.*\(...\)$/\1/'`
echo $version
also gives only 121
What does echo $file_name give you? It shows only one line with your code.. Asker had multiple lines in that variable
export version=`echo "$file_name" | sed 's/.*\(...\)$/\1/'`
echo $version
gives
112 121
but the asker did not specify any variables
the asker did say "I have series of of file names"
which might be a series of variables
the asker also said "I need to get last three characters(112 or 121 or 131 etc"
112 or 121 is not the same as "112 121"
echo $version
gives
112 121
but the asker did not specify any variables
the asker did say "I have series of of file names"
which might be a series of variables
the asker also said "I need to get last three characters(112 or 121 or 131 etc"
112 or 121 is not the same as "112 121"
In the original post, he posted two lines..
right(stringname,3)