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!

Pattern match assistance

Status
Not open for further replies.

tonykent

IS-IT--Management
Jun 13, 2002
251
0
0
GB
I've got a data file containing lines in 2 basic formats e.g.

1 f none /usr/stdapp/cnvcmd/cnvcmd.ast 0666 root other 22681
and
0003d000gh0root/usr/.install/stdapp/defapp/cat008/enccat.ast

I want a pattern match will will pull out the file name with its path from both types of rows. I can get it to work with one or the other but not both! Can you do better? Thanks.
 
For the two lines you posted this works:
Code:
m!(/.*?)[^/\w.]!; # file captured into $1
You'll have to be more specific about the format if that doesn't work in all cases.

jaa
 
/(\/\S+)/ && print "$1\n";

This prints both file names.
The pattern just means "a slash followed by one or more
non-whitespace characters."
 
this could work too.. in case there's a space in the filename

Code:
m ~ ( /.*/        # everything between first and last slash
          \w+     # followed by a word
              \.  # a dot
          \w+)    # another word
      ~x;

-or-

m~( /.*/\w+\.\w+)~x;
 
Actually, I was thinking if there was a space in the path.. mine won't work if there's a space in the filename.
 
can you guarantee one of two things:
a) the filename ends in '.ast'
b) the filename ends with a three character extention, ie /\.\w{3}/ ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Thanks for all the responses guys. I'll try them out when I get into work tomorrow.

The filename extensions vary and are not all 3 letters long.
 
Thanks very much to you all. I went with dummy33's solution in the end. The data file was somewhat more complicated than I went into but this solution coped with it all successfully.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top