试图弄清楚为什么带有awk的bash代码无法正常工作

问题描述 投票:0回答:1
#!/bin/bash _subtitles_getSubtitlesForUrl() { local awkCode2= read -r -d "" awkCode2 << 'SEARCHFORIDSAWKEOF' BEGIN { fileSize = 0 fps = 0 time = 0 } /td align="center"><p>0/ { isTimeMatched = match($0, /td align="center"><p>0[^0-9]*([0-9\.]+)/) if (isTimeMatched) { time = substr($0, RSTART + 22, RLENGTH - 16) } } /Rozmiar pliku/ { isFileSizeMatched = match($0, /Rozmiar pliku:[^0-9]*([0-9\.]+)/) if (isFileSizeMatched) { fileSize = substr($0, RSTART + 18, RLENGTH - 14) } } /Video FPS/ { isFpsMatched = match($0, /Video FPS:[^0-9]*([0-9\.]+)/) if (isFpsMatched) { fps = substr($0, RSTART + 15, RLENGTH - 15) } } /napiprojekt:/ { isHrefMatched = match($0, /href="(napiprojekt:[^"]*)"/) if (isHrefMatched) { printf("%7s | fps: %6s |%10s | %s\n",time ,fps ,fileSize , substr($0, RSTART + 6, RLENGTH - 7)) } } SEARCHFORIDSAWKEOF cat 1.html | busybox awk "$awkCode2" } _subtitles_getSubtitlesForUrl
bash awk
1个回答
0
投票
操作中显示(即“移动”一个块)。

键入捕获变量中的

time
数据,然后在匹配
napiprojekt:
时生成输出
td align=\"center\"><p>0
进行这两组更改后,代码生成:
2

######### # replace this: time = substr($0, RSTART + 22, RLENGTH - 16) # with this: printf("%7s | fps: %6s |%10s | %s\n",substr($0, RSTART + 22, RLENGTH - 16) ,fps ,fileSize , napi_data) ######### # replace this: printf("%7s | fps: %6s |%10s | %s\n",time ,fps ,fileSize , substr($0, RSTART + 6, RLENGTH - 7)) # with this: napi_data = substr($0, RSTART + 6, RLENGTH - 7)

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.