Remove XML comments using Regex in bash

前端 未结 4 1261
清酒与你
清酒与你 2021-01-06 19:40

I want to remove XML comments in bash using regex (awk, sed, grep...) I have looked at other questions about this but they are missing something. Here\'s my xml code

<
4条回答
  •  不知归路
    2021-01-06 20:25

    The most simple solution to remove all comments from a textfile I could come up with is:

    sed 's//-->\x0/g' | grep -zv '^\0
    
    
            
        
    
    

    Than the grep -z will treat that character as "line separator"

    • \n
    • \n\n\n \n \n
    • \n

    grep -v will remove the middle part.

    And finally tr -d will remove the \0 again.


    In this case it should be applied to both files before comparing e.g.:

    diff <(sed 's//-->\x0/g' file1.xml | grep -zv '^/-->\x0/g' file2.xml | grep -zv '^/-->\x0/g' | grep -zv '^
         
     
    热议问题