[英]i got line from html file using grep in unix script, but i can't figure out how to extract text using sed
i'm making a shell script that shows title and an artist of a song that is played on the radio. 我正在制作一个shell脚本,显示标题和电台播放的歌曲的艺术家。 i got html file and i found the line that i needed, using grep, but can't figure out how to extract the text that i need. 我得到了html文件,并使用grep找到了所需的行,但无法弄清楚如何提取所需的文本。 the line that i got is 我得到的是
<div class="n Title">title, different every time </div><div class=n Artist">artist that changes also</div>
how do i extract the title and the artist using unix commands? 如何使用Unix命令提取标题和艺术家? i have tried many ways but it didn't work properly. 我已经尝试了许多方法,但是无法正常工作。
grep -Po 'Title">\K[^<]*'
gives you title, same idea you can get the Artist. 给您标题,您可以获得艺术家的相同想法。 but keep in mind, using regex to "parse" xml/html is risky, for example, the website change the html source, make this in separated lines... or they add some other attributes, or add some other css classes after Title
... 但请记住,使用正则表达式来“解析” xml / html是有风险的,例如,网站更改html源,将其分隔成行...或者它们添加一些其他属性,或在Title
之后添加一些其他CSS类...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.