LinuxQuestions.org
Help answer threads with 0 replies.
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 10-01-2007, 10:11 AM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 491

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


Hello,

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:
Code:
/client/1388a/Screen Shot-21_10_2006.PNG
and I need to have an output like:
Code:
/client/1388a/
To summary's: I want to remove every thing which is after the last "/" of the line.


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

Rep: Reputation: 35
If in a variable:

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

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

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

Rep: Reputation: 21
Quote:
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
Code:
$ dirname "/client/1388a/Screen Shot-21_10_2006.PNG"
/client/1388a
 
  


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


All times are GMT -5. The time now is 11:30 AM.

Main Menu
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