Link to home
Start Free TrialLog in
Avatar of klopter
klopter

asked on

monas - Why does perl -pe 's/^.*?($|\t.*?($|\t))//' permissions.dat > output_file work?

This question is for monas if s/he wants it.  If monas hasn't responded in a week, I'll consider other answers.

Here is what I can figure out:

perl -pe 's/regex//' input > output
  Strips all occurrences of the regular expression regex from the file


^         matches the beginning of a line
.*        matches one or more characters

\t        matches the tab character
-e        accepts a command on the command line
$         matches the end of line
|         means or

Here is what I don't understand:

?
-e       alone produces no output, -pe works fine

perldoc perlre   suggests that "?" is not a regular
expression meta-character and points me to perldoc perlop.

perldoc perlop refers to "?:" but not "?"perl -pe 's/^.*?($|\t.*?($|\t))//' permissions.dat > output_file itself - or else I did not find it.

Thanks,
  Ken


Avatar of klopter
klopter

ASKER

Last paragraph should read:

perldoc perlop refers to "?:" but not "?"
itself - or else I did not find it.

Avatar of ozo
Where does perldoc perlre suggest that "?" is not a regular expression meta-character?
it says
                 The following standard quantifiers are recognized:
                     *      Match 0 or more times
                     +      Match 1 or more times
                     ?      Match 1 or 0 times
                     {n}    Match exactly n times
                     {n,}   Match at least n times
                     {n,m}  Match at least n but not more than m times
-e means that the actual script is on the command line, rather than the NAME of the script FILE.

-p means:
Open the data file, pass each line to the script, and print $_ to stdout after each line is processed.



.*   matches everything up to the line terminator.  It is 'greedy'.

The '?' in  .*?x   makes the .* non-greedy.  ('x' represents one or more characters forming part of the regex.)

The  .*?  in  .*?x  will match any characters, but will will terninate when if finds x.  In your example, x is ($|\t.*?($|\t)).
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
klopter,

I came too late. Please award people who answered you.
Avatar of klopter

ASKER

Thanks.  Sorry for the delay.

Ken