Reputation: 11
I would like to use awk to work on some files. I have a file like this:
input:
a 2 16
b 17 25
c 26 32
d 33 51
and what I want is to split all rows to enumerate the range between column 2 and column 3, incrementing the numbers by 2. For example:
a 2 4 6 8 10 12 14 16
b 17 19 21 23 25
c 26 28 30 32
d 33 35 37 39 41 43 45 47 49 51
Upvotes: 1
Views: 78
Reputation: 17851
$ awk ' { printf("%-3s", $1)
> for (i=$2; i<=$3; i+=2)
> printf ("%-3d", i)
> printf("\n") } ' <<EOF
> a 2 16
> b 17 25
> c 26 32
> d 33 51
> EOF
a 2 4 6 8 10 12 14 16
b 17 19 21 23 25
c 26 28 30 32
d 33 35 37 39 41 43 45 47 49 51
Upvotes: 4