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.

Revisions

  1. DaWe35 created this gist Oct 14, 2024.
    30 changes: 30 additions & 0 deletions srt_to_txt.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/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."