Delete all rows that have a specific string

1

I would like to delete all rows that have the string Excluído , searching from a specific string to the end of another string. Example:

<p class="FolderPath">
    <table class="DiffTable">
        <tr>
                <td class="DiffName">
                    <a name="I36676">
                    </a>
                </td>
                <td>
                    Excluído no destino
                </td>
           </tr>
         </table>
</p>

It would delete all the lines that have the string Excluído in the middle of them, starting the string search from <p class="FolderPath"> to the </p> string. I know how to delete the line containing the string:

sed '/Excluído/d' arquivo.txt
  

How would you delete N lines? starting from <p class="FolderPath"> to string </p> ?

    
asked by anonymous 04.12.2015 / 14:11

2 answers

1

Using Perl:

perl -n0E 'say grep !/Excluído/ , split(/(<p class="FolderPath">.*?<\/p>)/s)'

where:

  • split(/(<p class="FolderPath">.*?<\/p>)/s) splits the input file by paragraphs and their intermediate
  • say grep !/Excluído/ prints drives that do not contain "Deleted"
  • perl -n0E process the file all at once
04.12.2015 / 16:50
2

I made a quick solution here, then added a more "polished".

sed -n '/DiffTable/,/<\/p>/p' arquivo.html |grep -q Excluído && sed '/"DiffTable"/,/<\/p>/{//!d}' arquivo.html || echo "Palavra buscada nao existe"

Parameters:

sed -n '/ DiffTable /, /

/ p' file.html | grep -q Deleted & &

Sed will extract all content between DiffTable and < / p > and with grep, we check if the Excluded string exists.

sed '/ "DiffTable" /, /

/ {//! d}' file.html

This is where we do the override, excluding all lines of DiffTable and

. The {//! D} parameter keeps the lines of the tags searched for, if you want to delete, switch to just d

|| echo "Word searched does not exist"

Just to warn that the word was not found in grep

    
04.12.2015 / 16:27