LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-25-2006, 05:10 PM   #1
dtcs
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, 05:15 PM   #2
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

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

Last edited by ygloo; 12-25-2006 at 05:20 PM.
 
Old 12-25-2006, 05:29 PM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

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


Reply


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 5 07-28-2014 07:25 AM
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 07:53 PM
Remove string in sed twantrd Programming 7 09-13-2006 03:28 PM
[bash / sed] remove all data between < > Ljohan Programming 4 03-15-2006 06:20 AM
Using sed in bash to remove whitespace jimieee Programming 3 01-28-2004 11:33 AM


All times are GMT -5. The time now is 04:54 AM.

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