How to use sed to extract substring

前端 未结 5 1681
执笔经年
执笔经年 2020-12-07 18:23

I have a file containing the following lines:

  
  &         


        
5条回答
  •  無奈伤痛
    2020-12-07 19:15

    You should not parse XML using tools like sed, or awk. It's error-prone.

    If input changes, and before name parameter you will get new-line character instead of space it will fail some day producing unexpected results.

    If you are really sure, that your input will be always formated this way, you can use cut. It's faster than sed and awk:

    cut -d'"' -f2 < input.txt
    

    It will be better to first parse it, and extract only parameter name attribute:

    xpath -q -e //@name input.txt | cut -d'"' -f2
    

    To learn more about xpath, see this tutorial: http://www.w3schools.com/xpath/

提交回复
热议问题