The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
List files with full path mr_bold Shell Programming and Scripting 3 10-07-2008 09:19 AM
list all files with full path of the file Sowser UNIX for Advanced & Expert Users 4 02-13-2007 02:46 PM
cp list of files into another directory pavan_test UNIX for Dummies Questions & Answers 4 05-08-2006 06:08 PM
list of files in one Directory venkyA UNIX for Dummies Questions & Answers 3 06-24-2005 01:49 PM
Removing duplicate files from list with different path vino Shell Programming and Scripting 10 05-12-2005 05:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-18-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore
Posts: 7
Question List the files without directory path

Hi

I am writing a script to find the list of files in dir1 and my script is place in dir2

while doing ls of files dir1 it is displaying with path. I would like to omit the path and display the only file name so that I can pass it to my script as arguments.


for filename in $datafiles/*.dat
#cat $filename |
do
echo "in for loop $filename "
grep -i "dummy file" $filename > /dev/null || echo $filename >> temp
if [ -s temp ]
then
touch checkfile
fi
done

This script is taking the path also .


Any help Appreciated


Thank you
Madan
Reply With Quote
Forum Sponsor
  #2  
Old 07-18-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,031
Something like this?
Code:
echo "./somedir1/somedir2/somefile"| sed 's!.*\/\([^\/]*\).*!\1!g'
somefile
#or
echo "./somedir1/somedir2/somefile"| awk -F"/" '{print $NF}'
somefile
And please use [c o d e] and [/ c o d e] to display code, ty
Reply With Quote
  #3  
Old 07-18-2008
jhtrice's Avatar
Registered User
 

Join Date: Jun 2008
Posts: 63
Use the basename command. Checkout man basename.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0