0

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/

  • 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
6
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

  • 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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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