Vex Star

Vex Star

Computers and Programming

Vex Star RSS Feed
 
 
 
 

Text parsing help… perl?

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.

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.
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
to do that to a file… the regex might look like:
perl -pi -w -e ’s/(^c5t|d0s2$)//g’ filename

to do that to a file… the regex might look like:
perl -pi -w -e ’s/(^c5t|d0s2$)//g’ filename

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.

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.

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

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.

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply