Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove characters inline

Status
Not open for further replies.

tagyourit

Technical User
Oct 20, 2008
22
US
I've got a perl script running on AIX that issues an MySQL select against a table and pulls back four columns of data.

name port status host

I'm getting stuff in the status column that I want to remove, specifically in the column status, if I get

down (Administratively down)

I want to remove (Administratively down) and only keep the down before the parens.

Here's my line that prints it all out...is there a way to strip that out here

while ( $cth->fetch() ) {
print "$MDS \t$PORT \t$STATUS \t$DESC\n";


or in the bind_columns line prior?
 
my ($new_status) = $STATUS =~ /^(\w)/;



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
It appears to be removing the entire column. From this:

host001 port25 down (Administratively down) node001

to:

host001 port25 node001

I wondered if the parens needed escaped thinking perl may be trying to interpret them as part of the regex

=~ /^\(\w\)/;

But that didn't change the output
 
let me add that it's actually removing the entire column??

so this

host001 port25 down (Administratively down) node001
host002 port27 up node002
host003 port29 up node003
host004 port31 down (Administratively down) node004

to this

host001 port25 node001
host002 port27 node002
host003 port29 node003
host004 port31 node004
 
ended up with this and it's working

$STATUS =~ s/\(.*\)//;

I think \w was matching and eliminating everything in that column.
 
where you printing STATUS or $new_status? I pushed the info in to a new variable. I originally was going to use .* but figured why go that broad when \w should get the world.. but maybe I was wrong.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I'm surprised that isn't working backwards of what you want. Basically giving you everything between the ()'s.

() tells perl what to capture, if you escape them it becomes part of what it is going to look for.

Travis

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
i was printing &new_status, but not in the right spot, I moved it down and now it's working, but with results I didn't entirely expect. Not in a bad way, actually, might work better.

before:
host001 port25 down (Administratively down) node001
host002 port27 up node002
host003 port29 up node003
host004 port31 down (Administratively down) node004

after:
host001 port25 d node001
host002 port27 u node002
host003 port29 u node003
host004 port31 d node004

Why do you think it's only printing the first letter? I figured ^( says start with the first ( character?
 
^ says start at the beginning
\w says word character
the ()'s say capture what is between these to put in to that variable.
I didn't have perl on the machine I was on but I just loaded it and you can use this
=~ /^(\w*)/;

Capture any word characters from the beginning of the string.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top