![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Please give us an example, I don't understand which part of the pathname you want to extract ???
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
Brilliant! Works perfectly. Thanks!
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|