Q:

How to repeat a sequence of numbers in a column using awk command

My input file contains data like this.
//address: 9050004 data: 1 id: 1 len: 0 size: 2
//address: 9050008 data: 1 id: 2 len: 0 size: 2
//address: 902e004 data: 1 id: 3 len: 0 size: 2
...
//address: 902e008 data: 1 id: 799 len: 0 size: 2
//address: 9096004 data: 1 id: 800 len: 0 size: 2
//address: 9096008 data: 1 id: 801 len: 0 size: 2
//address: 9097004 data: 1 id: 802 len: 0 size: 2
...
//address: 902e008 data: 1 id: 1599 len: 0 size: 2
//address: 9096004 data: 1 id: 1600 len: 0 size: 2
//address: 9096008 data: 1 id: 1601 len: 0 size: 2
//address: 9097004 data: 1 id: 1602 len: 0 size: 2

from the above data, id value should not cross 800. The sequence must be repeated like 1,2,...799,1,2...799.
so my output should be like below
//address: 9050004 data: 1 id: 1 len: 0 size: 2
//address: 9050008 data: 1 id: 2 len: 0 size: 2
//address: 902e004 data: 1 id: 3 len: 0 size: 2
...
//address: 902e008 data: 1 id: 799 len: 0 size: 2
//address: 9096004 data: 1 id: 1 len: 0 size: 2
//address: 9096008 data: 1 id: 2 len: 0 size: 2
//address: 9097004 data: 1 id: 3 len: 0 size: 2
...
//address: 902e008 data: 1 id: 799 len: 0 size: 2
//address: 9096004 data: 1 id: 1 len: 0 size: 2
//address: 9096008 data: 1 id: 2 len: 0 size: 2
//address: 9097004 data: 1 id: 3 len: 0 size: 2

Could someone please help me in getting the above one in awk command?

A:

To wrap back to 1 when reaching 800, you will have to recalculate that column as ((id - 1) % 799) + 1, where % is the modulus operator:
$ awk '/^\/\// { $6 = (($6 - 1) % 799) + 1; print }' file
//address: 9050004 data: 1 id: 1 len: 0 size: 2
//address: 9050008 data: 1 id: 2 len: 0 size: 2
//address: 902e004 data: 1 id: 3 len: 0 size: 2
//address: 902e008 data: 1 id: 799 len: 0 size: 2
//address: 9096004 data: 1 id: 1 len: 0 size: 2
//address: 9096008 data: 1 id: 2 len: 0 size: 2
//address: 9097004 data: 1 id: 3 len: 0 size: 2
//address: 902e008 data: 1 id: 1 len: 0 size: 2
//address: 9096004 data: 1 id: 2 len: 0 size: 2
//address: 9096008 data: 1 id: 3 len: 0 size: 2
//address: 9097004 data: 1 id: 4 len: 0 size: 2

Note that in your expected output, the id for address 902e008 is 799.  This is not possible if you're restricting the range to [1, 799].

