Solved

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

Posted on 2006-11-30
2
466 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 215
Different colored text in ComboBox without Subclassing 8 76
sum67 challenge 35 128
matchUp  challenge 6 82
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

732 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