Re: Cut patten between slashes

Jens.Toerring_at_physik.fu-berlin.de
Date: 05/22/04

  • Next message: Nick Landsberg: "Re: Cut patten between slashes"
    Date: 22 May 2004 12:29:50 GMT
    
    

    Wyatt <itlrn@techie.com> wrote:
    > I have a file listed as

    > /dir1/sd11/sd111/sd1111/file1
    > /d2/sd2/file2
    > /d3/sd31/sd34/sd345/sd3456/sd34567/file3

    > I want to extract only filenames from this and write them into another file

    > file1
    > file2
    > file3

    > How do I do this ? Anyhelp is appreciated.

    If the input file is named "i.dat" and the output file "o.dat" the
    following are some of many ways you can do it with Perl:

    perl -e 'while (<>){/^([^\/]*\/)*(.*)$/; print "$2\n";}' < d.dat > o.dat
    perl -n -e '/.*?([^\/]*)$/;print $1' < d.dat > o.dat
    perl -n -e 's/.*?([^\/]*$)/$1/;print' < d.dat > o.dat
    perl -e 'while(split "/", <>){print @_[-1];}' < d.dat >o.dat
    perl -n -e 'split "/";print @_[-1];' < d.dat > o.dat
    perl -n -e 'print((split "/")[-1])' < d.dat > o.dat

                                     Regards, Jens

    -- 
      \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
       \__________________________  http://www.toerring.de
    

  • Next message: Nick Landsberg: "Re: Cut patten between slashes"