Skip to content

Instantly share code, notes, and snippets.

@DaWe35
Created October 14, 2024 07:43
Show Gist options
  • Save DaWe35/6746408768c66eb57ef29bd160f459d7 to your computer and use it in GitHub Desktop.
Save DaWe35/6746408768c66eb57ef29bd160f459d7 to your computer and use it in GitHub Desktop.
SRT to TXT converter (removes lines 1, 2, 4)
#!/bin/bash
# Input and output files
input_file="input.txt"
output_file="output.txt"
# Initialize line counter
line_counter=0
# Remove output file if it exists
> "$output_file"
# Read the input file line by line
while IFS= read -r line
do
# Increment the line counter
line_counter=$((line_counter + 1))
# If line is 3rd in the group, write it to the output file
if (( line_counter % 4 == 3 )); then
echo "$line" >> "$output_file"
fi
# Reset the counter after every 4 lines
if (( line_counter % 4 == 0 )); then
line_counter=0
fi
done < "$input_file"
echo "Finished processing the file. Output saved in $output_file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment