awk filters the required content in the web page - the road to dream building

Background information

In order to realize the dynamic update of the download link, store it in the QQ collection. Each update only needs to change the link in the collection, and there is no need to change the script content.

Note: When collecting files, special symbols need to be added to distinguish them from the source code of the web page to facilitate extraction of links.

How to filter with awk

 Commonly used parameters

print        #用来输出数据,其使用格式是:print $1,$2,$3... 其中,各个项目之间需要使用逗号进行分隔,然后在输出时,这些项目会以空白字符串作为分隔符。
NR        #打印行数
NF        #打印列数
-F:        #指定输入字段分隔符,默认为空格。

 Example:

#将提取到的下载链接赋值给变量A,再使用curl -O命令进行下载
#grep命令将包裹在书名号中的内容提取出来《》;awk负责过滤书名号,只保留书名号中的内容部分
A=$(curl -s https://sharechain.qq.com/7c28db2e2bd03cf6375160b0586f41ab|grep -Eo '《.*?》'|awk -F'[《》]' '{print $2}'|head -n 1) && curl -O ${A}

make a note

Guess you like

Origin blog.csdn.net/qq_34777982/article/details/135018811