Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

spetznatz

macrumors regular
Original poster
I'm using Grok to translate .srt (subtitle) files (its translation quality is pretty good). But, lately, it's been messing up the output files by removing the carriage returns / line breaks between each timestamp / text block, rendering the .srt files useless, despite my prompt telling Grok to preserve carriage returns and line breaks and to only output valid .srt format.

You can see the input file on the left and the output file on the right.

GrokProb.jpg


I'm using TextEdit.app to process the .srt files (cleanup and formatting). I also have BBEdit (free version). Is there any way I can automate the insertion of carriage returns in the output file (e.g. searching for / replacing control characters)? Basically, I need a way of inserting a \r (carriage return) before each line number...

TIA
 
Last edited:
Hah! Solved it by asking Grok to write a more explicit prompt than the one I'd been using..!!!
 
BBEdit supports regex, so if you're familiar with those, it seems doable.

Another possibility is to preformat the original file with a pattern that won't be removed, replacing blank lines with "--##--" or something similar. Then run it through the translation, and finally a cleanup pass that restores "--##--" to a blank line.

You'd probably have to experiment to find something that won't be translated or removed. It looks like numbers with punctuation are making it through, so maybe "--9999--". It can be anything unambiguous that doesn't otherwise appear. For example, I used four 9's because I don't see any of those in the timestamps. It's conceivable the numbers could reach that high.
 
why not just script this? Save
#!/bin/bash
# Usage: ./fix_srt.sh input.srt > output.srt

awk '
/^[0-9]+$/ && prev != "" { print "" }
{ print; prev = $0 }
' "$1"
save as fix_srt.sh - text file (ASCII) in the folder with your mangled .SRT files. run:

chmod +x fix_srt.sh
n the terminal to make it executable.

run
./fix_srt.sh input.srt > output.srt
to fix the files.


EDIT: OP fixed via prompt 💪🙃 - @spetznatz like to document your prompt here?
 
  • Like
Reactions: chown33
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.