发现里面有贝壳串PDF [英] Find string inside pdf with shell

查看:124
本文介绍了发现里面有贝壳串PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有什么办法来检查是否存在使用shell脚本 PDF 文件中的字符串?我一直在寻找这样的:

 如果[搜索(字符串,pdf_file)] GT; 0,则
   回声存在
科幻


解决方案

正如西蒙很好地指出,可以使用简单的转换 PDF 纯文本 pdftotext ,然后,只需搜索你要找的东西。

转换后,您可以使用的grep ,bash的正则表达式,或者你想要的任何变化:

 而读线;做    如果[[$ {线} =〜[0-9] {4}( -  [0-9] {2}){2}]];然后
        回声>>>发现日期;
    科幻完成< ≤(pdftotext infile.pdf - )

I'd like to know if there is any way to check if there is a string inside a pdf file using a shell script? I was looking for something like:

if [search(string,pdf_file)] > 0 then  
   echo "exist"
fi

解决方案

As nicely pointed by Simon, you can simply convert the pdf to plain text using pdftotext, and then, just search for what you're looking for.

After conversion, you may use grep, bash regex, or any variation you want:

while read line; do

    if [[ ${line} =~ [0-9]{4}(-[0-9]{2}){2} ]]; then
        echo ">>> Found date;";
    fi

done < <(pdftotext infile.pdf -)

这篇关于发现里面有贝壳串PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆