![]() |
|
|
|
|
|||||||
| 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 |
|
#8
|
|||
|
|||
|
Okay, now I'm having another problem with my script.
If I type: Code:
echo {12..18}
12 13 14 15 16 17 18 However, my script looks like this: Code:
echo "Input first set of nodes"
read node1 # This is where you insert the string of numbers
result=`echo $node1 | sed -r -e 's/([0-9]+)-([0-9]+)[ ]*/{\1..\2} /g'`
echo $result
Thanks again. |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Quote:
Code:
sed -e 's/([0-9]+)(-)([0-9]+)/{\1..\3}/g' file
|
|
#10
|
|||
|
|||
|
Thanks for the correction. I really was not sure. sed is fairly new to me, trying to pick up on it in my spare time. I should have known though, in this regards sed and perl are very very similar, -e -i and etc, the regular expression syntax appears to be identical as well.
|
|
#11
|
||||
|
||||
|
Hi.
Quote:
Code:
#!/bin/bash3 -
# @(#) user1 Demonstrate eval.
# echo "Input first set of nodes"
# read node1 # This is where you insert the string of numbers
node1="12-18"
result=`echo $node1 | sed -r -e 's/([0-9]+)-([0-9]+)[ ]*/{\1..\2} /g'`
echo {1..5}
eval echo $result
exit 0
Code:
% ./user1 1 2 3 4 5 12 13 14 15 16 17 18 |
|
#12
|
|||
|
|||
|
Awesome! Thanks drl, it worked perfectly.
Hopefully I only have one more question now. I do what you suggested, and I want to sort the output of "eval echo" numerically, so I do this: Code:
#!/bin/bash3 -
# @(#) user1 Demonstrate eval.
# echo "Input first set of nodes"
# read node1 # This is where you insert the string of numbers
node1="435-437,476-492 70-72,76,80-86"
result=`echo $node1 | sed -r -e 's/([0-9]+)-([0-9]+)[ ]*/{\1..\2} /g'`
echo {1..5}
eval echo $result | sort -n
exit 0
Thanks again in advance, and thanks for the link! |
|
#13
|
||||
|
||||
|
Hi.
The result of the final echo is a single line, so it is already in the correct order as sort looks at it. What exactly are you looking for? If you were doing this manually, how would you go about it? Note that you have interspersed a comma (,) at places in the list ... cheers, drl |
|
#14
|
|||
|
|||
|
Quote:
I'm sorry, I didn't mean to have those comma's in there. Even with no comma's in the line, it still doesn't sort. I guess I need to come at the whole thing from a different angle? All I basically need it to do is take a list of numbers, like this: 435-437 70-72 76 80-86 and print the ranges and sort all of it numerically. |
|||
| Google The UNIX and Linux Forums |