Results 1 to 6 of 6
Hi!
I need some help with bash scripting.
I have a string of the type:
'nuber1/number2/number3 some text'
I need to extract numerical values in the variables. What is the ...
- 11-28-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 7
help with a script needed
Hi!
I need some help with bash scripting.
I have a string of the type:
'nuber1/number2/number3 some text'
I need to extract numerical values in the variables. What is the easiest way to do this?
Thank you!
- 11-28-2007 #2
- 11-28-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 7
Thanks for the hint. No, this is not a homework... I need to extract number of cylinders, heads and sectors from the log file and to use them to start the other program. Here is my code... It works, but seems a bit ugly, are there any better way to do this?
Code:cyl=`grep "number of cyl" log.txt | sed -n 's/\([0-9][0-9]*\)\/[0-9][0-9]*\/[0-9][0-9]*.*/\1/p'` head=`grep "number of cyl" log.txt | sed -n 's/[0-9][0-9]*\/\([0-9][0-9]*\)\/[0-9][0-9]*.*/\1/p'` sect=`grep "number of cyl" log.txt | sed -n 's/[0-9][0-9]*\/[0-9][0-9]*\/\([0-9][0-9]*\).*/\1/p'`
- 11-28-2007 #4
I guess its fine like this. I cant do sed at all so if it works it should just be fine right? ^^
What you might want to do is:
Since I noticed you did read the same logfile for the same thing three times.Code:Share=`grep "number of cyl" log.txt | sed -n 's/\([0-9][0-9]*\)\/[0-9][0-9]*\/[0-9][0-9]*.*/\1/p'` cyl=$Share head=$Share sect=$Share
- 11-28-2007 #5Just Joined!
- Join Date
- Nov 2007
- Posts
- 7
I read 3 different values from the same line, which contains keyword...
cyl/head/sect keyword and more text...
May be someone knows a way to do this in one pass?
- 11-28-2007 #6Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Show us the strings you have and the output you desire.
Regards


Reply With Quote