-4

I have a news article which I need to edit up a bit. Basically, I need to search for all lines that do not contain characters t and h 2 or more times in a row and replace 4 letter words with character D in those lines. Have no idea where to start. For example, I have this text

Animals are multicellular eukaryotic organisms which form a biological kingdom Animalia. 
Historically, Aristotle divided animals into those with blood and those without

And I want it to look like

Animals are multicellular eukaryotic organisms which D a biological kingdom Animalia.
Historically, Aristotle divided animals into those with blood and those without
  • You should definitely start by providing or creating an example of what the text that is to be parsed looks like. If you leave the question as is, the wrath of U&L users will be upon you before you can get an answer. You did not even specify what you mean by H and V in a row, as It could be HHHH/VVVV or HV – BarBar1234 Oct 23 '19 at 2:10
  • This would probably be better on the Vim Stackexchange. Also, where do you say t and h more than 2 times in a row on the second line? – Nick Matteo Oct 23 '19 at 2:28
  • Sorry, I meant 2 or more times in a row. – Marcus Littereal Oct 23 '19 at 2:32
  • Have you tried anything so far? By showing your attempts and describing what parts you are having difficulty with, we get a better understanding of your proficiency and can give a more precise answer. As it stands, it just looks like you've posted a requirement and want someone to write your code for you. – Ingo Karkat Oct 23 '19 at 9:10
  • Your line contains 2 t's in the row?! mul*t*icellular eukaryo*t*ic – Lieven Keersmaekers Oct 23 '19 at 10:00
0

If your file name is called Myfile.txt you can run:

grep -Ev '[Tt][Tt]|[Hh][Hh]' Myfile.txt |  awk '{ gsub("([^[:alnum:]]|^)[[:alnum:]]{4}([[:space:]]|[[:punct:]])"," D ");print $0}' > MyEditedFile.txt

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.