在 Linux 中搜索多个 Excel (xls) 文件中的文本

Dhe*_*rik 5 linux microsoft-excel

我使用的是 Ubuntu Linux,但找不到在多个 excel ( xls) 文件中查找文本的方法。我的愿望是通过命令行执行此操作,但也欢迎其他替代方案。

Dhe*_*rik 4

我使用 ssconvert 工具(来自 Gnumeric)制作了一个。您需要先安装 Gnumeric:

sudo apt-get install gnumeric
Run Code Online (Sandbox Code Playgroud)

您可以将内容保存为脚本并调用:

./script-find-in-xls.sh text
Run Code Online (Sandbox Code Playgroud)

脚本的内容。

#!/bin/sh

# $1 - text to find

if [ -z "$1" ]
  then
    echo 'Please, the text is mandatory'
    exit 1
fi

rm -rf /tmp/xls-csv/
mkdir /tmp/xls-csv/

cd /tmp/xls-csv/
cp /location/of/excel-files/*.xls /tmp/xls-csv/

for f in *.xls; do
    ssconvert -S --import-encoding=ISO8859-1 ./"$f" ./"${f%.xls}.csv"
done

cat *.csv.* > all-xls-content.txt
rm *.csv.*

if cat all-xls-content.txt | egrep --color $1; then
    echo 'found'
else
    echo 'not found'
fi
Run Code Online (Sandbox Code Playgroud)

该脚本将所有 xls 文件转换为 csv 文件,将 csv 文件合并为一个文件,然后使用egrep查找文本。

代码并不完美,但可以完成工作。