bash - lowriter Bash 脚本将所有 doc 就地转换为 pdf
问题描述
所以..我的任务是将一堆 *.doc 文件转换为 *.pdf 使用lowriter
我想做的是就地执行此操作,但由于无法使用 执行此操作lowriter
,我想我会捕获原始文件和路径,捕获转换,然后将转换后的文件移动到原始路径,并且然后删除原来的 *.doc
问题是我的sed
和或awk
充其量是弱的;)所以我无法弄清楚如何从输出中“捕获”转换后的文件名。
我的代码:
#!/bin/bash
FILES=/my/path/**/*.doc
shopt -s globstar
for f in $FILES; do
the_file=$f;
the_orig_dir=$(dirname "$the_file") ;
converted=$(lowriter --headless --convert-to pdf "$the_file");
echo $converted;
done;
输出是:
convert /my/path/Archives/Ally/Heavenly Shop.doc -> /my/Heavenly Shop.pdf using filter : writer_pdf_Export
convert /my/path/Archives/Ally2/Solutions Shop.doc -> /my/Solutions Shop.pdf using filter : writer_pdf_Export
convert /my/path/Archives/Ally3/Xpress Shop.doc -> /my/Xpress Shop.pdf using filter : writer_pdf_Export
我需要做的是->
在:
. 我只是不知道我该怎么做。有人可以告诉我吗?
解决方案
对您提出的问题的快速回答是,这将使用任何 sed:
sed 's/.*-> \(.*\) using filter :.*/\1/'
但我不确定你是否真的需要这样做。根据您发布的内容和您在问题下的评论,我认为您真正需要的是:
#!/usr/bin/env bash
shopt -s globstar
docPaths=( /my/path/**/*.doc )
for docPath in "${docPaths[@]}"; do
pdfPath=$(basename "$docPath" '.doc')'.pdf'
lowriter --headless --convert-to pdf "$docPath"
printf '%s\n' "$pdfPath"
done
推荐阅读
- java - 创建一个选择查询,如果 id 不存在,那么对于该 id,它应该在 SQL 中返回 null
- objective-c - 如何使用 Objective-C 获取任何文件的文件类型描述?
- google-sheets - 使用 OR 函数和 FALSE 语句的两个条件
- numpy - 从命令提示符运行时,Pyinstaller exe 无法执行 numpy 操作,但在 anaconda 提示符下的 conda env 可以正常工作
- javascript - 如何在 Javascript 中的嵌套对象中查找特定值
- google-maps - 如何使用 TileServer-GL 或 OpenMapTiles 服务器将多个 .pbf 文件而不是 .mbtiles 作为矢量切片提供到使用 Deck.GL MVTLayer 的 Google 地图中?
- sql - SQL 选择具有匹配所有 WHERE 子句的多个连接属性的项目
- computer-vision - 在 Colab 中使用“imgaug”进行图像数据增强未按预期工作
- angular - ngrx 实体 upsertOne 通过 selectId
- javascript - 如何退出 .JS 进程以便将 StdOut 值返回给 AHK?