gpt4 book ai didi

linux - 如何遍历文件以创建一系列新的.docx文件?

转载 作者:行者123 更新时间:2023-12-03 09:59:22 25 4
gpt4 key购买 nike

背景

我有一个像这样的文件名file:

something.txt
another.cpp
whoa.cxx
...

我想在当前目录中为每个文件创建一个相应的文本文件:
./something.txt.docx
./another.cpp.docx
./whoa.cxx.docx

这应该是一个非常简单的操作...但是我想尝试的一系列命令似乎在逻辑上似乎没有意义:

尝试的解决方案
  • 用管道将一只猫抚摸:cat file | touch <not sure what to put here>.docx

    一个。如您所见,我不知道如何在遇到的每个文件名中附加.docx扩展名,而且我不知道以这种方式巧妙地进行正则表达式附加的方法。 touch手册页在这方面似乎也没有帮助。
  • 将猫放入xargs touch:cat file | xargs -I{} touch {}.docx
    一个。我的意图是使用-I option从字面上附加.docx以获得上面看到的结果。以下是-I的预期功能:

    -I replace-str

    Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.



    这引发了错误xargs: .docx: No such file or directory



  • 如何遍历文件并为文件中的每一行创建相应的.docx?

    最佳答案

    假设文件内容格式合理,并且没有奇怪的情况,您可以执行以下操作:

    while IFS= read -r line; do
    touch "$line.docx"
    done < input-file-name.txt

    我刚刚确认它可以在我的系统上运行。

    关于linux - 如何遍历文件以创建一系列新的.docx文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58597046/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com