开发者

Cat selected files fast and easy?

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 spli开发者_运维问答t 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..


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜