LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed: How to remove the end of a line? (https://www.linuxquestions.org/questions/programming-9/sed-how-to-remove-the-end-of-a-line-588634/)

angel115 10-01-2007 10:11 AM

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 :(

radoulov 10-01-2007 10:22 AM

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/


angrybanana 10-01-2007 10:29 AM

Quote:

Originally Posted by angel115 (Post 2909394)
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



All times are GMT -5. The time now is 09:15 PM.