rrthomas / mmv

Other
50 stars 7 forks source link

One-liner to append + concatenate? #21

Closed Geremia closed 2 months ago

Geremia commented 2 months ago

@rrthomas Is there a way to append a file to each of the matched files and then concatenate all those files, all in one line?

I know the following command doesn't work (due to there being 3 args), but I am trying to do something like this:

mad appendix \*.txt concatenated.txt

where appendix.txt is appended to all the *.txt files and those files (each with appendix.txt appended to them) are concatenated into one large concatenated.txt?

rrthomas commented 2 months ago

Can't think of one, sorry. Doesn't seem like a big deal to me, since you can use cat on the result of mad; is there some reason to want a single command?

Geremia commented 2 months ago

@Geremia Primarily speed. I have hundreds of thousands of files that I'd like to append to (for padding purposes). Using cat would slow things down.

Where in the code could I add padding to each file before they're concatenated?

rrthomas commented 2 months ago

If you're appending many thousands of files, how is using cat going to be slow?

Adding padding: isn't that just another use of mad?

Geremia commented 2 months ago

@rrthomas mad appendix.txt *.txt doesn't work (>2 args), and mad appendix.txt \*.txt simply creates a file named *.txt whose contents are appendix.txt. Am I missing something?

parallel mad ../appendix.txt {} ::: *.txt is far too slow (several minutes for me).

rrthomas commented 2 months ago

@rrthomas mad appendix.txt *.txt doesn't work (>2 args), and mad appendix.txt \*.txt simply creates a file named *.txt whose contents are appendix.txt. Am I missing something?

Sorry, indeed that won't work: you can append multiple sources to one target (so you can use mad instead of cat) but you can't append a single source to multiple targets (so you can't use mad to add the appendix to lots of files).

Geremia commented 2 months ago

@rrthomas Thanks for the clarification.

Geremia commented 2 months ago

@rrthomas Adding

         char null_byte = 0x00;
         write(t, &null_byte, 1);

at mmv.c#L1578 achieved what I was looking for. (I only wanted to append one null byte in my specific case to the end of each file before concatenating.)