Print String Every Specific Line

Dear All,

I have input file like this,

001
059
079
996
758
079
069
059
079
...
...

Desired output:

AA 001
BB 059
CC 079
DD 996
AA 758
BB 079
CC 069
DD 059
AA 079
...
...

print different string (AA,BB,CC,DD) every multiples of four.....

Thanks Advance,

Attila

Try something like:

awk 'BEGIN {
        p[0] = "DD"
        p[1] = "AA"
        p[2] = "BB"
        p[3] = "CC"
}
{       printf("%s %s\n", p[NR % 4], $0)}' input

As always, if you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk .

Or sth like this..

 
awk 'BEGIN{split("DD AA BB CC",P)}
{print P[NR%4+1],$0}' file

Not quite. In awk, + has higher precedence than % (so you're doing mod 5 rather than (mod 4) + 1). If you change the subscript in the 2nd line to (NR%4)+1 , you'd get what you wanted.

-------------------------------------
Ouch... I apologize. I was looking at unary + not binary +. Pamu's code is correct as written.

Sorry,
Don

you can use this also

  sed -e "1~4s/^/AA /g" -e "2~4s/^/BB /g" -e "3~4s/^/CC /g" -e "4~4s/^/DD /g" $file