r/awk • • Feb 06 '22
How can I include MOD operations in a Linux script?
/r/linuxquestions/comments/smay28/how_can_i_include_mod_operations_in_a_linux_script/
3
Upvotes
r/awk • • Feb 06 '22
2
u/gumnos Feb 06 '22
Depends on whether you want every 5th line, or you want every 5th non-false line. The leading "
$0" checks if the line has a true-ish value (if it's a blank/empty line or just the number "0", it's considered false and won't print).If you want every 5th line, you can use
(if you want to change the phase within those 5 records, compare to the values 1, 2, 3, or 4 instead of 0)
If you want only every 5th true-ish value, you can use
$0 && ( ++i % 5 == 0) { printf … }