First step, encapsulate that script in a file, and do not run it directly on the terminal (and lose the UUOC reward while we are on it).
#!/bin/bash
{
awk 'NR%4 == 2 { print $1 }' file.txt | sort | uniq -c | sort -gr >>output.txt
} 2>error.log
This captures all error messages in the file error.log. Then you can add diagnostic information.
#!/bin/bash
{
date >&2
set -x
awk 'NR%4 == 2 { print $1 }' file.txt | sort | uniq -c | sort -gr >>output.txt
date >&2
} 2>error.log
, . bash, , , , . , ( ), , ( , , , ).
script , output.txt, - error.log; script ( file.txt). , nohup & - .
file.txt ; . . . - script, .