--- Booher Timothy B 1stLt AFRL/MNAC <[EMAIL PROTECTED]> wrote:
> o.k. another regex issue . . . I want a one-liner that can remove everything
> after a given character: i.e.
> 
> in this case everything after ! (fortran comment):
> 
> would this work:
> 
> perl -npe 's/\!.+$//'
> 
> my thinking is that \! Is the literal character and . would count for
> anything + would represent any number of anything and $ would symbolize the
> end of the line. Am I close, if so how close?
> 
> Thanks so much,
> 
> tim

I don't know fortran, so I have no idea how likely this is, but what happens if you 
have an
exclamation point in quotes?  In many languages:

    print "some text!"...

You'd wind up with syntax errors.  Also, -n and -p are the same thing except -p prints 
the lines
and -n does not.  If you're sure that you won't have problems with exclamation points 
showing up
where you don't want them, try this:

    perl -pi.bak -e 's/(?:!.*)?$//' list of files

Here's how the regex breaks out:

    s/
       (?:       # not capturing parens (for grouping)
          !.*    #    and eclamation point followed by zero or more characters
       )?        # end grouping and make it optional (might not have a comment)
     $//x        # anchor to end of string and replace with nothing

The -i command line switch allows the in-place edit and the .bak automatically creates 
a backup of
the file with a .bak extension.

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to