AWK to print every nth line from a file

前端 未结 3 722
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 18:41

i want to print every Nth line of a file using AWK. i tried modifying the general format :-

awk \'0 == NR % 4\' results.txt

to:-



        
3条回答
  •  Happy的楠姐
    2021-01-04 19:06

    How about this:

    awk -v n="$ct" '0 == NR % n' results.txt
    

    or a bit shorter

    awk -v n="$ct" '!(NR % n)' results.txt
    

提交回复
热议问题