Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Regular Expression to extract a number from a variable value

Posted on 2008-10-14
3
Medium Priority
?
999 Views
Last Modified: 2008-10-27
Hi,

I am getting different set of values in a variable. These values can be adminWash4567.sh adminWash4567.txt eastLA7456.sh eastLA7456.txt westLA7825 oldSFB8523 etc. I basically am trying to extract the last 4 digits of the value which starts with "admin".
I think it should work something like this

if the value starts with "admin" save last 4 digits in a variable before the "." (as in adminWash4567.sh) and exit

it would be great if you can suggest a way to do this
0
Comment
Question by:LordSM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 800 total points
ID: 22715630
A generic solution is



value='adminWash4567.sh'
result=`echo "$value" | sed "s/admin.*\([0-9][0-9][0-9][0-9]\).*/\1/"`
echo $result

Open in new window

0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 400 total points
ID: 22715639
try

var=`echo  adminWash4567.sh | sed 's/[a-zA-Z\.]*//' | awk -F'.' '{ print $1 }'`
0
 

Accepted Solution

by:
LordSM earned 0 total points
ID: 22783118
Generic solution works

value='adminWash4567.sh'
result=`echo "$value" | sed "s/admin.*\([0-9][0-9][0-9][0-9]\).*/\1/"`
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question