?
Solved

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

Posted on 2006-11-30
2
Medium Priority
?
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
cjjclifford earned 500 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

771 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