Announcement

Collapse
No announcement yet.

Need to substring something

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need to substring something

    Hey Guys,

    First off you guys are such a great help with scripting and I greatly appreciate it.

    Ok so here is what I am trying to do. I am in the process of writing a script. But I need to set one of the variables equal to a substring from another script. So here is what I need.

    In my script I have a variable

    ADMINPORT=

    The = will be the result of cat otherscript | grep ADMIN_PORT

    What I need though is not the admin port but the actual port that comes after that.
    So if I run the command right now it will return the whole ADMIN_PORT=8011 but I just want the 8011.
    Thanks for you help with this in advance.
    Kubuntu II on both Laptop and Desktop and some servers here at the office

    #2
    Re: Need to substring something

    well, in basic it would be:

    right('ADMIN_PORT=8041', len('ADMIN_PORT=8041') - 11)

    obviously you would replace 'ADMIN_PORT=8041' with whatever variable you are using in the script...and the syntax might be a little different depending on the language used. hopefully this will get you started in the right direction.

    mm0
    Dell Inspiron 1720 Laptop<br />Intel T9300 Core2Duo Processor @ 2.5Ghz<br />4 GB Ram | 1920 X 1200 Resolution<br />2 X 160 GB SATA HD Internal<br />Nvidia GeForce 8600M Graphics Adapter<br />Using Kubuntu 9.10

    Comment


      #3
      Re: Need to substring something

      One option is to use use 'cut'
      Code:
      otherscript | grep ADMIN_PORT | cut -d= -f2
      (-d= uses '=' as a field delimiter, and -f2 prints field number 2)

      Comment


        #4
        Re: Need to substring something

        Hey thanks for both of those tips guys. I ended up using Kubicles suggestion and it worked like a charm. I love how with bash multiple ways to do something just depends on which way you decide to go.
        Kubuntu II on both Laptop and Desktop and some servers here at the office

        Comment

        Working...
        X