Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract number between characters

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
CA
I have a filename like PT.3_BUSHING-212389.csv

The only thing that is consistent is that a "-" comes before the number and a "." comes after.

How can I extract the 212389 to use in a variable.

I have tried

echo "PT.3_BUSHING-212389.csv" | sed -n '/-/,/./p'

thanks,
Jeff
 
Code:
echo "PT.3_BUSHING-212389.csv" | sed 's/.*-\([0-9][0-9]*\).*/\1/g'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
In a ksh compatible shell, you may try something like this:
a="PT.3_BUSHING-212389.csv";a=${a%.*};a=${a##*-};echo "$a"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks guys. I ended up using:

number=`echo PT.3_BUSHING-212389.csv | cut -f 2 -d '-' |cut -f 1 -d '.'`

and it worked the way I needed it to.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top