Cat 选择文件又快又简单?
直到现在我一直在终端中查找文件..但是完成很多工作后这很耗时。我想要的是这样的:
我有一个包含数百个文件的文件夹,并且我想有效地将几个文件放在一起。 例如,有没有办法(在Finder中)选择五个分割文件;
file.txt.001
、file.txt.002
、file.txt.003
、file.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为 sh 脚本工作。它将文件的内容通过管道传输到
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.从您对文件名的描述来看,您可以使用 bash 轻松实现自动化。例如,
这将合并一个目录中共享相同前缀的所有文件。
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.
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 usefind
instead.grep -o "^.*\."
will match everything up to the last dot in the file name (you could also usesed -e 's/.[0-9]*$/./'
to remove the last digits. uniq will filter all duplicates. Then you have something likespeech1.txt. sound1.txt.
in thePREFIXES
variable. The next line loops through those and merges the groups of files individually using the * wildcard.