Remove path from filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove path from filename
# 1  
Old 08-23-2007
Remove path from filename

In a foreach loop I end up with $file containing the filename INCLUDING the whole path. I want this reduced to just the filename, but I can't seem to remember how I did it some years back. I am sure I can do it with "sed", but I am pretty sure I have seen a simpler command.

Anyone?

borgeh
# 2  
Old 08-23-2007
Hi ..

Please post the path .. We can extract with CUT command ..


Thanks,
Arun
# 3  
Old 08-23-2007
basename $file will output just the filename.
# 4  
Old 08-23-2007
Thanks

Thanks....basename was what I was looking for. Frustrating when you know you know but can't get it out.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script - Remove the 3 top level of a full path filename

Hello. Source file are in : /a/b/c/d/e/f/g/some_file Destination is : /d/e where sub-directories "f" and "g" may missing or not. After copying I want /a/b/c/d/e/f/g/file1 in /d/e/f/g/file1 On source /a is top-level directory On destination /d is top-level directory I would like... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Sorting using filename of a path

Hi all! i have a question how do you sort the filename of a path directory according to alphabetic order. Example: sort according to highlighted text. There maybe space for filename Path=/home/pikamon/Desktop/ABC; Path=/home/pikamon/Desktop/ABD; Path=/home/pikamon/Desktop/Riduan la;... (5 Replies)
Discussion started by: pikamon
5 Replies

3. Shell Programming and Scripting

How to remove filename from the path

Hi, I have a list of paths with files at the end. How can strip off filenames. This is what I have: /apps/test/abc/file.txt /apps/new/home/daily/report.xml /apps/old/home/weekly/out/test.sh This is what I need: /apps/test/abc/ /apps/new/home/daily/ /apps/old/home/weekly/out/ ... (10 Replies)
Discussion started by: djanu
10 Replies

4. Shell Programming and Scripting

Split Filename from Absolute Path

Hello, I have the string "/a/b/c/ddd.txt" and i want to get only the filename, in this case "ddd.txt". I have as something known in the script the pattern "/a/b/c/", so I`ve tried something like: echo "/a/b/c/ddd.txt" | cut -d "/a/b/c/" -f2 but it doesn`t go, any help?. thanks, bye (2 Replies)
Discussion started by: rubber08
2 Replies

5. Shell Programming and Scripting

Getting filename with entire path without extension

Hi Experts, need one help.. m writing a shell script for which i need the entire path of the file but without its extension. running the below script gives error at the statement DIR = `dirname $FILE` --command not found. #!/bin/bash jar xvf *jar for FILE in `find . -name "*.class"` ... (3 Replies)
Discussion started by: amicableperson
3 Replies

6. Shell Programming and Scripting

remove a path from PATH environment variable

Hi I need a script which will remove a path from PATH environment variable. For example $echo PATH /usr/local/bin:/usr/bin:test/rmve:/usr/games $echo rmv test/rmve Here I need a shell script which will remove rmv path (test/rmve) from PATH... (9 Replies)
Discussion started by: madhu84
9 Replies

7. Shell Programming and Scripting

fnsplit, Extract filename from path

Hi all, I know this has been covered a lot, I have been searching and reading for hours on the subject, however so far I have been unsuccessful at accomplishing the goal using sed. I know this can be done with parameter expansion (Thanks cfajohnson for a great explanation of parameter... (5 Replies)
Discussion started by: Festus Hagen
5 Replies

8. Shell Programming and Scripting

to check whether a directory or filename path is valid or not

the script on excution should take a directory path from useran a numric input and it should check indicate whether its write or not? if the cmmd sh<script-name>,dir/path.<500>" is greater than 500 in size should be copied to dir ,temp in pwd and display the mesage'files of 2000 bytes hav been... (4 Replies)
Discussion started by: arukr
4 Replies

9. Windows & DOS: Issues & Discussions

get filename from absolute path in batch program

hey im writing batch program for the first time and i have almost finished it the only problem is that i want to extract basename from absolute path for eg : if my first argument is c:\abcd\xyz\temp.txt then i want only temp.txt in variable. and how do i extract some part from string for eg... (1 Reply)
Discussion started by: zedex
1 Replies

10. Shell Programming and Scripting

Replace a filename with full path using sed

hi, i need to replace a line a file with a new raw device location.. original file.. /opt/sybase/ASE1502/ASE-15_0/bin/dataserver \ -d/data/TST_AKS1/sybdevices/master.dat \ -e/logs/sybase/TST_AKS1/SFO_TST_AKS1.log \ -c/apps/sybase/ASE1502/ASE-15_0/TST_AKS1.cfg \... (2 Replies)
Discussion started by: aksaravanan
2 Replies
Login or Register to Ask a Question