Re: Cut patten between slashes

From: Charles Demas (demas_at_TheWorld.com)
Date: 05/22/04

  • Next message: Chris F.A. Johnson: "Re: Cut patten between slashes"
    Date: Sat, 22 May 2004 17:59:33 +0000 (UTC)
    
    

    In article <2h8vduF9j32cU1@uni-berlin.de>,
     <Jens.Toerring@physik.fu-berlin.de> wrote:
    >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

    wouldn't this in sed be simpler:

    sed 's:.*/::' d.dat > o.dat

    though just using the unix basename command seems even easier.

    Chuck Demas

    -- 
      Eat Healthy        |   _ _   | Nothing would be done at all,
      Stay Fit           |   @ @   | If a man waited to do it so well,
      Die Anyway         |    v    | That no one could find fault with it.
      demas@theworld.com |  \___/  | http://world.std.com/~cpd
    

  • Next message: Chris F.A. Johnson: "Re: Cut patten between slashes"

    Relevant Pages

    • Re: sort files by exif date
      ... >> and the filenames in a list, sort, then extract the filenames again. ... >> Probably a few lines of shell script. ... That string will be a line of text. ...
      (comp.unix.questions)
    • Re: A silly question about tar
      ... Florian Kulzer wrote: ... filenames in one line, separated by spaces. ... It looks like the "extract" action interprets the first filename ... not the tar command itself. ...
      (Debian-User)
    • Re: Cut patten between slashes
      ... On 2004-05-22, Wyatt wrote: ... > I want to extract only filenames from this and write them into another file ... and may be copied under the terms of the GNU General Public License ...
      (comp.unix.questions)
    • Re: finding a value in a string
      ... if you see the filenames that i have mentioned, ... within the last 5-6 characters. ... thats a sort of version number and thats what i am looking to ... extract. ...
      (microsoft.public.excel.misc)
    • Re: sort files by exif date
      ... list of filenames, extract the required data from the files and put it and the filenames in a list, sort, then extract the filenames again. ... Probably a few lines of shell script. ...
      (comp.unix.questions)