对于 excel 调用 shell 脚本中的每一行

For each Raw in a an excel call shellscript

xlsx 有一些像

这样的行
OP20
MA20

对于 excel 中的每一行,我需要调用一个 shell 脚本作为参数

while read p; do
 ./command.sh $p
done <Name.xlsx

我有这样的代码,但在 运行 代码之后,我得到了一些垃圾字符作为输出。

bash

中的 XLS 文件

您必须将 .xls 文件转换为 ASCII:

xls2csv Name.xlsx | xargs -d $'\n' -n 1 ./command.sh

xargs将运行 ./command.sh逐行一次,连续,每行作为参数。

xml2csv备选方案:

您可以为此使用 libreoffice 命令行:

soffice --convert-to "csv" Name.xlsx
xargs -d $'\n' -n 1 ./command.sh <Name.csv
基于

libreoffice 的解决方案使用 tab 而不是 coma:

soffice --convert-to 'csv:Text - txt - csv (StarCalc):9,34,UTF8' --headless file.xlsx
while IFS=$'\t' read -aru ${tsv} array;do
    echo "Line: $array"   # show first field
    declare -p array
done {tsv}<file.csv