Computing.Net > Forums > Unix > substring extraction

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

substring extraction

Reply to Message Icon

Name: ohuang
Date: March 20, 2009 at 07:45:49 Pacific
OS: AIX
Subcategory: General
Comment:

I'd like extract information from a string that is anything after ".".
for example, if I have:

-c/rs/rs36/tap/config.76

I'd like to extract the info after "." which is "76" in this case.

any help would be appreciated




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 20, 2009 at 08:46:22 Pacific
Reply:

There are any number of ways. Here are two:

#!/bin/ksh

string="-c/rs/rs36/tap/config.76"

# 1
v=$(echo "$string"|awk ' BEGIN { FS="." } { print $2 } ')
echo $v

# 2
set - $(IFS="."; echo $string)
echo $2


0

Response Number 2
Name: ghostdog
Date: March 22, 2009 at 19:01:44 Pacific
Reply:

with bash

# string="-c/rs/rs36/tap/config.76"
# echo ${string##*.}
76



0

Response Number 3
Name: ohuang
Date: March 23, 2009 at 11:45:24 Pacific
Reply:

Thank you both for your responses. I got it workin now.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: substring extraction

substring extraction www.computing.net/answers/unix/substring-extraction/7343.html

IF condition after substr www.computing.net/answers/unix/if-condition-after-substr/4000.html

Awk substring problem www.computing.net/answers/unix/awk-substring-problem/4897.html