2

I have 30+ text files that I want to remove specific lines of text from. They all have different names (which I need to keep), they are in the same folder. The text will not all be on the same line but will be identical.Some are single words, some are multiple lines. I have looked at various ways of doing this -but am at a bit of a loss. I've also looked at using macros (in LO) and python and am still stuck! I also have versions of these files as Libre office writer(.odt) but would rather use the text files ( I saved them as .txt to get rid of formatting etc)

I'm new to linux and have limited experience...and after much reading around I tried this in cli first cd to the directory/folder containing the files then sed -i.bak 'text to be deleted'/d'* I tried this with one word and with several lines ( a paragraph) - nothing happened! I think I'm missing something! Lots of what I've read mentions using line numbers or line starting with etc -but in my case (if possible) it would be better to use the text A kind of find and replace, replace with nothing. I could open and do find and replace on each file but there is a lot of text I need to get rid of -it would several processes in each file.
Just thought I should also say some of the files don't contain all the text I am trying to get rid of.

Thanks for any help

5
  • Try: sed -i.bak 's/text to be deleted//' *.
    – harrymc
    Aug 17, 2021 at 13:50
  • Thanks - that is working. I need to use the right case but that's not a big deal. . Just one issue - I am getting a .bak copy for every change - I don't need a back up copy (as I have the .odt files) -is there a way of stopping that? Or can I list more than one change? (both would be great...if possible)
    – Unlucky 83
    Aug 17, 2021 at 14:23
  • 1
    Don't use -i.bak, just -i.
    – harrymc
    Aug 17, 2021 at 17:23
  • Thanks again - that's so much help. I am getting an issue with some of the text containing brackets eg Name(s) or long text (pg 1), text etc (see pg 2). Is there a way around that? Thanks again for your help - it is making a tiresome task much easier!
    – Unlucky 83
    Aug 19, 2021 at 7:17
  • Names with special characters are a problem. For safer ways of handling file-names, see at the end of this article or the complete discussion at this article.
    – harrymc
    Aug 19, 2021 at 7:52

1 Answer 1

0

This formulation worked for the poster:

sed -i.bak 's/text to be deleted//' *

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .