grep multiple commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Elizabeth H
    New Member
    • Jan 2011
    • 19

    grep multiple commands

    Hi

    Below is what I am trying to do. I have a variable which contains a list of commands seperated by ":". While trying to use a for loop to get each command, it doesnt retrun the correct results

    Example:

    Code:
    var="command -1:command -2*: command something*"
    for c in `echo $var | tr ':' ' '`
    do
      echo $c
    done
    
    Instead of getting the below
    command -1
    command -2*
    command something
    
    I get
    command
    -1
    command
    -2*
    command
    something
    Please help
    Last edited by zmbd; Nov 5 '12, 08:08 PM. Reason: [Z(Please use the <CODE/> button to format your code)]
  • rampdv
    New Member
    • Feb 2013
    • 7

    #2
    Hi i am providing the answer using Perl programming,can u just check u r language also,there must be a split command ,u use that command u get output as u required manner.

    Code:
    $var="command -1:command -2*: command something*";
    @commands = split(/:/,$var);
    foreach $comm (@commands) {
    
    print " $comm \n ";
    }
    if there is any chance don't have any split funtion in u r language ,please use regular expression
    Last edited by Rabbit; Mar 1 '13, 04:37 PM. Reason: Please use code tags when posting code.

    Comment

    Working...