Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 94
Generic progress indicator 6 109
bigDiff challenge 17 75
fizzArray  challenge 1 47
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now