Modify the file by script

Hi All,
I have an input file like below,

6984 1225
6989 1220
6994 1214
6999 1207
7004 1199
7009 1192
7014 1184
7019 1177
7024 1170
7029 1162
7034 1154
7039 1145
7044 1137
7049 1129
7054 1123
7059 1119
7064 1115
7069 1112
7074 1109
7079 1107
7084 1106
7089 1106
7094 1107
7099 1110
7104 1114
7109 1120
7114 1126
7119 1132
7124 1137
7129 1140
7134 1146
7139 1156
7144 1172
7149 1193
7154 1229
7159 1276
7164 1332
7169 1378
7174 1411
7179 1439
7184 1452
7189 1448
7194 1444
7199 1440

I want the ouput file to be

6984 1165(1145+20) )
delete all the 10 NR's from head part and tail part except the first and the last and replace the 2nd column value of the last and the first as given.
7039 1145
7044 1137
7049 1129
7054 1123
7059 1119
7064 1115
7069 1112
7074 1109
7079 1107
7084 1106
7089 1106
7094 1107
7099 1110
7104 1114
7109 1120
7114 1126
7119 1132
7124 1137
7129 1140
7134 1146
7139 1156
7144 1172
delete all the 10 NR's from head part and tail part except the first and the last and replace the 2nd column value of the last and the first as given.
7199 1192(ie 1172+20)

It shud be very simple to you xperts but I can not make it.
Thanks a lot.
Please help
Arnab

Sorry, but I don't understand the request. You give us the input & desired output but what logic should be applied to the input? Maybe I'm being stupid, but what is an NR other than an awk option? I can easily add a few numbers but your request doesn't give me anything to really go on. Sorry.

Do you mean:-

  1. The first column from the first line : The second column from the 12th line plus ten
  2. Display next 22 lines
  3. The first column from the 12th line : The second column from the 33rd line plus ten

One is confused and wonders.:confused:

Exactly as I felt when I read the post :slight_smile:

one way,

awk -v n=`wc -l < file` '
 NR==1 {r1=$1} 
 NR==12 {s1=$2+20} 
 NR==n {r2=$1} 
 NR==n-11 {s2=$2+20} 
 NR >11 && NR <= n-11 {a[NR] = $0} 

END {print r1 FS s1; for (i=12;i<=n-11;i++){print a};print r2 FS s2} ' file

Output:

6984 1165
7039 1145
7044 1137
7049 1129
7054 1123
7059 1119
7064 1115
7069 1112
7074 1109
7079 1107
7084 1106
7089 1106
7094 1107
7099 1110
7104 1114
7109 1120
7114 1126
7119 1132
7124 1137
7129 1140
7134 1146
7139 1156
7144 1172
7199 1192

I will try to post more efficient solution later.
I think this could be done all inside awk