The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-15-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Help with sed

Hi Guys,

I know this is probably really easy but I've just started learning the basics of this stuff.

Im trying to extract the number from a whole bunch of filesnames and store then as variables in my bash script.

So for instance my filename is dim24.15c.07/junk/altmag6082Jb7J1f5.txt, all the characters are fixed from one file name to the next but the numbers vary, I need to get the number out, I'm reading the sed manual, anybody know the answer quickly?
Reply With Quote
Forum Sponsor
  #2  
Old 01-15-2008
Registered User
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
If you want to sort 6082Jb7J1f5 from dim24.15c.07/junk/altmag6082Jb7J1f5.txt with altmag fixed, you can do this :
Code:
file=dim24.15c.07/junk/altmag6082Jb7J1f5.txt

number=$(basename $file .txt | cut -c7-)

echo $number
Reply With Quote
  #3  
Old 01-15-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Well sort of, the problem is I dont know how many number I need or anything else really. The only thing I have is the "template" dimxxyyczz/junk/altmaga...kJbfJ1fc.txt

Im trying to extract xx,yy,zz,a...k,c so I can use them as variables.
Reply With Quote
  #4  
Old 01-15-2008
Registered User
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
Please give us an example, I don't understand which part of the pathname you want to extract ???
Reply With Quote
  #5  
Old 01-15-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Apologies, basically Im trying to extract each number and set a variable equal to its value.

file=dim24.15c.07/junk/altmag6082Jb7J1f5.txt

So I need some like $a = .15, $b = .07, $c=6082, $d = 7, $e = 1, $f = 5 in this case.

Thanks for you help. Its greatly appreciated.
Reply With Quote
  #6  
Old 01-15-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
if "." is not needed.
Code:
# file=dim24.15c.07/junk/altmag6082Jb7J1f5.txt
# set -- `echo $file | tr -s '[a-zA-Z/.]' ' '`
# echo $1
24
# echo $2
15
Reply With Quote
  #7  
Old 01-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Brilliant! Works perfectly. Thanks!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0