Welcome to the most active Linux Forum on the web.
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 10-01-2007, 11:11 AM   #1
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 535

Rep: Reputation: 79
sed: How to remove the end of a line?


I need to remove the end of a line, so for this I think that sed will do the job but i didn't manage to do that.

here is a sample of my input:
/client/1388a/Screen Shot-21_10_2006.PNG
and I need to have an output like:
To summary's: I want to remove every thing which is after the last "/" of the line.

Here is what I use so far:
sed -e 's/[\ a-z0-9A-Z\.\_\-]*$//g'
but the space are not handled correctly
Old 10-01-2007, 11:22 AM   #2
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 37
If in a variable:

% v="/client/1388a/Screen Shot-21_10_2006.PNG"
% echo "${v%/*}/"
With sed (only as an example):

% sed 's /[^/]*$ / ' <(echo "/client/1388a/Screen Shot-21_10_2006.PNG")

Last edited by radoulov; 10-01-2007 at 11:27 AM. Reason: added the trailing slash :)
Old 10-01-2007, 11:29 AM   #3
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Originally Posted by angel115 View Post
I need to remove the end of a line, so for this I think that sed will do the job but i didn't manage to do that.
If you're not dead set on using sed you can check if you have the 'dirname' command
$ dirname "/client/1388a/Screen Shot-21_10_2006.PNG"


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
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 10:42 AM
PHP Remove Line From Shoutcast Playlist File. Sed? windisch Programming 2 03-26-2007 09:52 PM
sed question: remove decoration from each line Hivemind Linux - Software 1 01-18-2006 08:13 AM
[SOLVED] delete the end of each line in a file with sed angel115 Linux - Newbie 3 11-16-2005 05:41 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM > Forums > Non-*NIX Forums > Programming

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

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