Text parsing help... perl?

Discussion in 'OT Technology' started by trouphaz, Jul 10, 2008.

  1. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0
    Ok, I know there has to be a way to do this easier than what I'm doing now. I have a list like this:
    c5t50060E80000000000000811C00000B0Cd0s2
    c5t50060E80000000000000811C00000B0Bd0s2
    c5t50060E80000000000000811C00000B0Ad0s2

    I want to strip out the c5t at the beginning and the d0s2 at the end. I figure I can dump it into a text file and just do a search/replace in vi, but I do shit like this enough that I'd like to understand how to do it with perl.

    Anyway, this list is the std out of another command.
     
  2. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0
    command | sed -e "s:c5t::" | sed -e "s:d0s2::"

    i know i could do it with sed too and probably awk if i knew it well enough, but i figured this would be a good place to start poking around perl.
     
  3. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,454
    Likes Received:
    12
    i'd just use cut in this situation to get the wwid out of the solaris disk name

    command | cut -b 4-35

    only works if you have less than 10 controllers, else need logic for the extra digit in c
     
  4. EkriirkE

    EkriirkE Zika Xenu OT Supporter

    Joined:
    Jan 11, 2004
    Messages:
    14,799
    Likes Received:
    0
    Location:
    Dublin & San Francisco, CA
    to do that to a file... the regex might look like:
    perl -pi -w -e 's/(^c5t|d0s2$)//g' filename
     
  5. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0
    that worked simply with:
    command | perl -pi -w -e 's/(^c5t|d0s2$)//g'

    ok, i see what is going on with that. the 's/(^c5t|d0s2$)//g' seems like something that should work in sed or even vi, but it doesn't.
     
  6. EkriirkE

    EkriirkE Zika Xenu OT Supporter

    Joined:
    Jan 11, 2004
    Messages:
    14,799
    Likes Received:
    0
    Location:
    Dublin & San Francisco, CA
    sed and vi probably omit the first "s"


    edit:nm. try putting a '%' before the s for vi sed may be the same, dunno...


    %s/(^c5t|d0s2$)//g
     
    Last edited: Jul 10, 2008
  7. trouphaz

    trouphaz New Member

    Joined:
    Sep 22, 2003
    Messages:
    2,666
    Likes Received:
    0
    i'm familiar with the search and replace format and it is identical except the OR that you have in there. so, in perl it seems to allow for ^c5t OR d0s2$. sed and vi just seem to treat (^c5t|d0s2$) as a single string.
     

Share This Page