Re: Cut patten between slashes

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 05/22/04


Date: 22 May 2004 20:00:37 GMT

On 2004-05-22, Wyatt 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.

awk -F/ '{print $NF}' FILE

   Or:

sed 's|^.*/||' FILE

   Or:

while read path
do
  echo ${path##*/}
done < FILE

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: Cut patten between slashes
    ... Wyatt wrote: ... > I want to extract only filenames from this and write them into another file ... because fools are so ingenious" ...
    (comp.unix.questions)
  • 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: 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)