Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-25-2006, 04:10 PM   #1
LQ Newbie
Registered: Jul 2005
Distribution: Slackware, Debian
Posts: 28

Rep: Reputation: 15
how to remove path using sed

I am trying to remove the path name and only get the file name
when I do this on the prompt it works:
cat a.txt | sed "s/.*\///"
when I do it from a script:
f=`cat $file | sed s/.*\///`
echo $f
it gives me an error:
sed: -e expression #1, char 7: unknown option to `s'
what am I doing wrong?
Old 12-25-2006, 04:15 PM   #2
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
try ' instead of "
sed 's/.*\///'

Last edited by ygloo; 12-25-2006 at 04:20 PM.
Old 12-25-2006, 04:29 PM   #3
Senior Member
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (
Posts: 1,900

Rep: Reputation: 68
Well, don't you really want to use 'basename' utility instead? Though ygloo is right.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SED - remove last four characters from string 3saul Linux - Software 9 12-14-2015 04:43 PM
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 06:53 PM
Remove string in sed twantrd Programming 7 09-13-2006 02:28 PM
[bash / sed] remove all data between < > Ljohan Programming 4 03-15-2006 05:20 AM
Using sed in bash to remove whitespace jimieee Programming 3 01-28-2004 10:33 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:16 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration