Search code examples
unixrowtrimcat

Remove rows inside txt file - unix


i need to remove some particular rows in a txt files considering a particular value. In particular i need to delete all the rows that cointain this syntax.

Row to deleted   
0311MUX                          31.03.2020

In the report i have rows like below one that should not be deleted since after mux i have a code.
0311MUX23453                     31.03.2020

Could you please help me on this? Thank you


Solution

  • Something like

    printf '%s\n' 'g/^0311MUX[[:space:]]/d' w | ed -s file.txt
    

    Will delete all rows from the file starting with that string followed by whitespace (to avoid deleting your other row with 0311MUX as a prefix).

    Or

    perl -ni -e 'print unless /^0311MUX\b/' file.txt