print every nth line into a row using gawk

To print every second line, starting with the first:

awk 'NR%2==1' file.txt

To print every tenth line, starting with the tenth line:

awk 'NR%10==0' file.txt

To use this in a script, add the following to a file called script.awk:

BEGIN {
    print "Processing file"
}

NR%10==0

END {
    print "Finished processing"
}

Then execute:

awk -f script.awk file.txt

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)