Cat 选择文件又快又简单?

发布于 2024-10-18 01:23:35 字数 554 浏览 7 评论 0原文

直到现在我一直在终端中查找文件..但是完成很多工作后这很耗时。我想要的是这样的:

我有一个包含数百个文件的文件夹,并且我想有效地将​​几个文件放在一起。 例如,有没有办法(在Finder中)选择五个分割文件;

file.txt.001file.txt.002file.txt.003file.txt.004 >

.. 然后在 Finder 中右键单击它们,然后单击合并?

我知道这当然不可能开箱即用,但是使用 Automator 操作、droplet 或 shell 脚本,是否可以做到类似的事情?或者也许为该猫操作分配一个键盘快捷键,当在 Finder 中点击选定的文件时,将自动合并到一个新文件并放置在同一文件夹中,名称基于原始拆分文件?

在此示例中,file.001 到 file.004 会神奇地出现在同一文件夹中,作为名为 fileMerged.txt 的文件?

我有大约一百万个此类分割文件,因此高效的工作流程将是我的救星。我正在写一本互动书,出版商给了我这个任务。

I have been cat'ing files in the Terminal untill now.. but that is time consuming when done alot. What I want is something like:

I have a folder with hundreds of files, and I want to effectively cat a few files together.
For example, is there a way to select (in the Finder) five split files;

file.txt.001, file.txt.002, file.txt.003, file.txt.004

.. and then right click on them in the Finder, and just click Merge?

I know that isn't possible out of the box of course, but with an Automator action, droplet or shell script, is something like that possible to do? Or maybe assigning that cat-action a keyboard shortcut, and when hit selected files in the Finder, will be automatically merged together to a new file AND placed in the same folder, WITH a name based on the original split files?

In this example file.001 through file.004 would magically appear in the same folder, as a file named fileMerged.txt ?

I have like a million of these kind of split files, so an efficient workflow for this would be a life saver. I'm working on an interactive book, and the publisher gave me this task..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

几度春秋 2024-10-25 01:23:35
cat * > output.file   

作为 sh 脚本工作。它将文件的内容通过管道传输到 output.file 中。
* 扩展到目录中的所有文件。

cat * > output.file   

works as a sh script. It's piping the contents of the files into that output.file.
* expands to all files in the directory.

奢华的一滴泪 2024-10-25 01:23:35

从您对文件名的描述来看,您可以使用 bash 轻松实现自动化。例如,

PREFIXES=`ls -1 | grep -o "^.*\." | uniq`
for PREFIX in $PREFIXES; do cat ${PREFIX}* > ${PREFIX}.all; done

这将合并一个目录中共享相同前缀的所有文件。

ls -1 列出目录中的所有文件(如果跨越多个目录可以使用 find 代替。grep -o "^.*\." 将匹配文件名中最后一个点之前的所有内容(您也可以使用 sed -e 's/.[0-9]*$/./' 删除最后一个数字。uniq然后您将在 PREFIXES 变量中得到类似 speech1.txt. 的内容,并单独合并文件组。使用 * 通配符。

Judging from your description of the file names you can automate that very easily with bash. e.g.

PREFIXES=`ls -1 | grep -o "^.*\." | uniq`
for PREFIX in $PREFIXES; do cat ${PREFIX}* > ${PREFIX}.all; done

This will merge all files in one directory that share the same prefix.

ls -1 lists all files in a directory (if it spans multiple directories can use find instead. grep -o "^.*\." will match everything up to the last dot in the file name (you could also use sed -e 's/.[0-9]*$/./' to remove the last digits. uniq will filter all duplicates. Then you have something like speech1.txt. sound1.txt. in the PREFIXES variable. The next line loops through those and merges the groups of files individually using the * wildcard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文