1823228 Members
4403 Online
109648 Solutions
New Discussion юеВ

Re: strings

 
Penny Patch
Occasional Advisor

strings

These are my strings
version="5.9"
version="5.8"
version="5.7"
verison="5.6"
verison="5.5.1"

I always want to ignore the first number i.e "5" and print the rest of it without the digits and without the double quotes.
How do I do that?
Thanks.

14 REPLIES 14
Penny Patch
Occasional Advisor

Re: strings

Sorry..some mistakes in the previous message.Please ignore that one.
This is the new one.

These are my strings
version="5.9"
version="5.8"
version="5.7"
verison="5.6"
verison="5.5.1"

I always want to ignore the first number i.e "5" and print the rest of the number(s) without the PERIOD and without the double quotes.
How do I do that?
Thanks
Michael Schulte zur Sur
Honored Contributor

Re: strings

Hi,

assign a line to s$ and use
expr s$ : 'version=\"5\(.*\)\"'

if you want to read a file.
while read s
do
expr s$ : 'version=\"5\(.*\)\"'
done < file

greetings,

Michael
Bruno Ganino
Honored Contributor

Re: strings

Use command awk !
Bruno
Torino (Turin) +2H
Michael Schulte zur Sur
Honored Contributor

Re: strings

Hi,

assign a line to s$ and use
expr s$ : 'version=\"5.\(.*\)\"'

if you want to read a file.
while read s
do
expr s$ : 'version=\"5.\(.*\)\"'
done < file

greetings,

Michael
TSaliba
Trusted Contributor

Re: strings

hi
if you want print
version=9
version=8
..
execute the attached script
TS
jj
Penny Patch
Occasional Advisor

Re: strings

Thanks for your replies.
But these strings are not in the file. This will the output of uname -r command
#uname -r
5.9
#uname -r
5.5.1
.
.
.

Sorry for the confusion.
TSaliba
Trusted Contributor

Re: strings

ok
then you can run

uname -r | sed 's/\"//g' file.out | sed 's/\.//g' | cut -c2-4

Hope this help
jj
curt larson_1
Honored Contributor

Re: strings

uname -r | tr -d "\"." | cut -c 2-
TSaliba
Trusted Contributor

Re: strings

sorry
uname -r | sed 's/\"//g' | sed 's/\.//g' | cut -c2-4
jj
john korterman
Honored Contributor

Re: strings

Hi,
a little more detailed:
# echo $verison|awk -F. '{$1="";print$0}'

regards,
John K.

it would be nice if you always got a second chance
Michael Schulte zur Sur
Honored Contributor

Re: strings

Hi,

uname -r | awk '{print substr($0,3)}'

greetings,

Michael
Bruno Ganino
Honored Contributor

Re: strings

Well,
Also this case it is resolved with command awk.
uname -r | awk '{print substr($0,3)}'
Bruno

Torino (Turin) +2H
Patrick Wallek
Honored Contributor

Re: strings

You could also try:

# uname -r | awk -F 5. '{print $2}'
John Wright_1
Advisor

Re: strings

Hi,

# uname -r | sed 's/^[^\.]*\.//'

Cheers,
JW.