Solved

How do you pull out the file name from a full path in Unix ksh?

Posted on 2006-11-30
2
449 Views
Last Modified: 2013-12-26
How do you pull out the file name from a full path in Unix ksh? I only want the file name and cannot remember how I have do this in the past. Below is a sample of my code snippet. I want to preserve the original file name.

-----------------------------------
for fn in `ls -1p $source_dir/*`
do

  IFS=":"
  outFile=$fn.san

  print "Sanitizing File:$fn"

  cat $fn | while read record

  ## Do stuff

  mv $fn to $fn.san
done

0
Comment
Question by:rayskelton
2 Comments
 
LVL 11

Accepted Solution

by:
cjjclifford earned 125 total points
ID: 18045151
basename $fullpath


e.g.

$ mkdir -p /tmp/a/long/path/with/some/files
$ touch /tmp/a/long/path/with/some/files/filename.txt
$ basename /tmp/a/long/path/with/some/files/filename.txt
filename.txt


( "dirname" does the opposite - i.e. just get the directory of a given file...)

i.e.

$ dirname /tmp/a/long/path/with/some/files/filename.txt
/tmp/a/long/path/with/some/files
0
 

Author Comment

by:rayskelton
ID: 18045626
This works great, thanks
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question