Re: Cut patten between slashes
From: Charles Demas (demas_at_TheWorld.com)
Date: 05/22/04
- Previous message: Nick Landsberg: "Re: Cut patten between slashes"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: Cut patten between slashes"
- Next in thread: Nick Landsberg: "Re: Cut patten between slashes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Nick Landsberg: "Re: Cut patten between slashes"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: Cut patten between slashes"
- Next in thread: Nick Landsberg: "Re: Cut patten between slashes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|