i want to delete something from each line of file for example :-

i have the following path in file : /var/lib/svn/repos/b1me/products/payone/generic/code/core/db/fs-type /var/lib/svn/repos/b1me/products/payone/generic/code/fees/db/fs-type /var/lib/svn/repos/b1me/products/payone/generic/code/merchantserver/db/fs-type

i want to do something to become /var/lib/svn/repos/b1me/products/payone/generic/code/core/ /var/lib/svn/repos/b1me/products/payone/generic/code/fees/ /var/lib/svn/repos/b1me/products/payone/generic/code/merchantserver/

link|improve this question

You need to be more specific. Are these lines of data in a file, or a list of files, or what? If you give a bit of context, it'll help get answers. – Cylindric Sep 21 '10 at 13:27
Do you want to delete a string or you want to perform a substitution? – jscott Sep 21 '10 at 13:28
feedback

3 Answers

up vote 6 down vote accepted
sed -ie 's/db\/fs-type//g' FILENAME
or cat FILENAME | sed -e 's/db\/fs-type//g'

howto: http://www.grymoire.com/Unix/Sed.html

link|improve this answer
i try two command ... command cat FILENAME | sed -e 's/db\/fs-type//g' work :) thank you :) – Mohammad AL-Rawabdeh Sep 21 '10 at 13:56
feedback

cat input-file | sed 's/db\/fs-type//g' >output-file

link|improve this answer
This will strip the trailing slash, which the examples have left in. – Cylindric Sep 21 '10 at 13:32
I realised that and edited it just few seconds after posting. Strangely it doesn't show as being edited. – Iain Sep 21 '10 at 13:46
Edits done in a short period of time are consolidated by the system. This includes the initial entry of a post if it's within that timeframe. – Dennis Williamson Sep 21 '10 at 13:54
@Dennis Williamson: Thanks for the explanation, I'd assumed that was the case but didn't want @Cylindric's comment to be seen by others as incorrect. – Iain Sep 21 '10 at 14:13
feedback

It sounds like what you want to do is simple substitution, and for that the use of a tool like sed with simple regular expression matching is the classical means of achieving your goal. A simple search turns up a ton of links, but here are two that should get you started on your way:

Generally using sed for string replacement in a file: http://www.cs.hmc.edu/tech_docs/qref/sed.html

An example a little more specific to your situation: http://www.computing.net/answers/unix/replace-a-complex-string-using-sed/5811.html

This is one of the most common sorts of problems to solve, and solutions are fairly ubiquitous in the Linux community.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.