Arithmetic operation with awk

I have output like following in a file


usmtnz-dinfsi19
72
71
38
1199
1199
0.8
19:23:58
usmtnz-dinfsi19
72
71
38
1199
1199
0.8
19:24:04
usmtnz-dinfsi19

I want to divide 5 & 6 line entries with 1000 .. how can i do it with awk

awk 'NR == 5 || NR == 6 { print $1 / 1000 }' filename

Thanks but it only displays line 5 and 6 i want all the lines and line 5 and 6 divided by 1000 and line 7 subtracted from 100 :slight_smile:

awk 'NR == 5 || NR == 6 { $1 = $1 / 1000 }
     NR == 7 { $1 = 100 - $1 }
     { print }
' filename

Ok that one worked Thanks again :b: but the file on which i 'm running this has n no. of entries like following

And we want this should go on 5,6,7 lines of all the resources

usmtnz-dinfsi19
72
71
38
1.199
1.199
99.2
19:23:58
usmtnz-dinfsi19
72
71
38
1199    <--
1199    <--
0.8      <--
19:24:04
usmtnz-dinfsi19
72
71
38
1199    <--
1199    <--
0.8      <--
19:24:11

How do you expect to get a real answer if you keep changing the question?

To change the script to do what you want, modify the selectors.

Just describing the problem accurately will give you a hint as to what you should do.

Ok i apologize for it. but i was thinking the answer you gave will solve my problem, which it didn't , anywayz thanks for all the help. It will be great if you can answer my last question.

Just replace all the NR with NR%8.

Indeed it is important that you give a clear problem description. Another approach:

xargs -n8 <infile|awk '{$5/=1000;$6/=1000;$7=100-$7}1' OFS="\n"

Yes that helped me and was able to modify the script thanx to all for the help
Special Thanks to Mr. Johnson