我使用下面的awk脚本来这样做,
for line in $1
do
grep -F ".js" $1 | awk '{print $7}' | sort -u
done 输出就快到了:
/blog/wp-includes/js/swfobject.js?ver=2.2
/fla/AC_RunActiveContent.js
/include/jquery.js
/include/jquery.jshowoff2.js
/include/jquery.jshowoff.min.js
/include/js/jquery.lightbox-0.5.js
/scripts/ac_runactivecontent.js我尝试了管道:剪切-d "/“-f5整数的awk,但部分脚本名称也被切断。
ac_runactivecontent.js HTTP
AC_RunActiveContent.js HTTP
jquery.jshowoff2.js HTTP
jquery.jshowoff.min.js HTTP
jquery.js HTTP
js
wp-includes如何从模式.js提取到分隔符"/“,以便只获得脚本文件名:
swfobject.js
AC_RunActiveContent.js
jquery.js
jquery.jshowoff2.js
jquery.jshowoff.min.js
jquery.lightbox-0.5.js
ac_runactivecontent.js发布于 2022-08-09 17:48:23
使用单一的for/grep/awk/sort (和可选的sort)替换当前的sort可能会更有效。
设置:
$ cat filename.js
1 2 3 4 5 6 /blog/wp-includes/js/swfobject.js?ver=2.2 8 9 10
ignore this line
1 2 3 4 5 6 /fla/AC_RunActiveContent.js 8 9 10
1 2 3 4 5 6 /include/jquery.js 8 9 10
ignore this line
1 2 3 4 5 6 /include/jquery.jshowoff2.js 8 9 10
1 2 3 4 5 6 /include/jquery.jshowoff.min.js 8 9 10
ignore this line
1 2 3 4 5 6 /include/js/jquery.lightbox-0.5.js 8 9 10
1 2 3 4 5 6 /scripts/ac_runactivecontent.js 8 9 10awk的一个想法是:
awk '
/.js/ { n=split($7,a,"[/?]") # split field #7 on dual characters "/" and "?", putting substrings into array a[]
for (i=n;i>=1;i--) # assuming desired string is toward end of $7 we will work backward through the array
if (a[i] ~ ".js") { # if we find a match then ...
print a[i] # print it and break out of the loop ...
next # by going to next input record
}
}
' filename.js
# or as a single line:
awk '/.js/ {n=split($7,a,"[/?]"); for (i=n;i>=1;i--) if (a[i] ~ ".js") { print a[i]; next}}' filename.js这就产生了:
swfobject.js
AC_RunActiveContent.js
jquery.js
jquery.jshowoff2.js
jquery.jshowoff.min.js
jquery.lightbox-0.5.js
ac_runactivecontent.js注意:如果需要, OP可以将结果输送到sort
发布于 2022-08-09 19:23:30
由于您已经在使用awk,@markp提供的答案可能是您的最佳选择。如果您对其他选项开放,则可以使用grep和basename的组合。(请注意,由于将grep输出到basename,这可能会降低效率)
使用@markp提供的答案中的示例文件,如下所示:
grep -o ' /.*\.js' tt.dat | xargs basename产生以下输出:
swfobject.js
AC_RunActiveContent.js
jquery.js
jquery.jshowoff2.js
jquery.jshowoff.min.js
jquery.lightbox-0.5.js
ac_runactivecontent.js发布于 2022-08-10 08:46:34
使用awk,您可以从第7列打印文件名的匹配。
模式[^/]+\.js匹配1+乘以除/以外的任何字符,后面跟着匹配的.js。
例如,使用file作为输入:
awk '
match($7, /[^/]+\.js/) {
print substr($7, RSTART, RLENGTH)
}
' file输出
swfobject.js
AC_RunActiveContent.js
jquery.js
jquery.jshowoff2.js
jquery.jshowoff.min.js
jquery.lightbox-0.5.js
ac_runactivecontent.jshttps://stackoverflow.com/questions/73295911
复制相似问题