LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 04: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, 04: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 04:20 PM.
 
Old 12-25-2006, 04:29 PM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

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


Reply



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 12 01-16-2023 10:21 AM
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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 PM.

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
Open Source Consulting | Domain Registration