如何使用 cat (递归)读取文件夹中的每个文件并将其存储在文件中?

How to read each file in a folder using cat (recursively) and store it in a file?

我有一个包含 9k PDF 文档的文件。我希望使用 cat 阅读它们每个的源代码(不是内容),并将它们存储在与 PDF 同名的单独文本文件中。

例如

cat 030.pdf > 030.txt

我想对文件夹中的所有文件执行此操作。我该怎么做?

您可以使用创建一个 shell 脚本来遍历目录中的文件并执行 cat 命令,然后将文件名添加子字符串以删除 .pdf 并添加 .txt:

for entry in "$search_dir"/*
do
  if [ -f "$entry" ];then
   cat "$entry" > "${entry%%.*}.txt"
fi
done

而不是使用 cat 使用 cp 它更有效率。

find . -name \*.pdf -exec cp {} $(basename {}).txt \;