How to get fields and get output with awk or shell script.?

I have a flat file A.txt with field seperate by a pipe

2012/11/13 20:06:11 |  284:hawk   pid=014268 opened Locations 12, 13, 14, 15 for /home/hawk_t112/t112/macteam/qt/NET12/full_ddr3_2X_FV_4BD_1.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|norway
2012/11/14 12:53:51 |  286:hawk   pid=012538 opened Locations 8, 9, 10, 11 for /home/hawk_t112/t112/macteam/qt/NET08/.try_3.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|norway
2012/11/14 14:23:19 |  288:hawk   pid=019275 opened Locations 0, 1, 2, 3, 4, 5, 6, 7 for /home/hawk_a108/a108/macteam/qt/NET24/full_111_ddr5_soq523_2X_FV.qt/dbFiles/a108.proto|2012/11/14 15:19:26 | still running |norway|norway

How do we use awk or shell program to get output file B.txt

2012/11/13 20:06:11 | Locations 12, 13, 14, 15|NET12/full_ddr3_2X_FV_4BD_1.qt|norway|norway22
** 22 is first location 12+10 ** Do not include in out put
2012/11/14 12:53:51 | Locations 8, 9, 10, 11|NET08/.try_3.qt|norway|norway18
** 18 is first Locations 8+10 *** Do not include in out put
2012/11/14 14:23:19 |Locations 0, 1, 2, 3, 4, 5, 6, 7 |NET24/full_111_ddr5_soq523_2X_FV.qt|norway|norway10
** 10 is first Locations 0+10 *** Do not include in out put

I hope you understand what i would like to get it from B.txt
Thanks.

Try this:

awk -F\| '{
  sub(/.*Locations /,"",$2)
  path=val=$2
  sub(/,.*/,"",val)
  val+=10
  sub(/ for.*/,"",$2)
  sub(/.*NET/, "NET",path)
  sub(/\.qt.*/, ".qt",path)
  print $1 FS " Locations " $2 FS path FS $5 FS $6 val}' A.txt > B.txt

Wow, it works beautiful. Thanks Chubler_XL
Now what if i have A.txt with extra 2nd field is 16

2012/11/13 20:06:11 |16|284:hawk   pid=014268 opened Locations 12, 13, 14, 15 for /home/hawk_t112/t112/macteam/qt/NET12/full_ddr3_2X_FV_4BD_1.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|norway
2012/11/14 14:23:19 |16|  288:hawk   pid=019275 opened Locations 0, 1, 2, 3, 4, 5, 6, 7 for /home/hawk_a108/a108/macteam/qt/NET24/full_111_ddr5_soq523_2X_FV.qt/dbFiles/a108.proto|2012/11/14 15:19:26 | still running |norway|norway
2012/11/14 14:23:19 |4|  288:hawk   pid=019275 opened Locations 0, 1 for /home/hawk_a108/a108/macteam/qt/NET24/full_111_ddr5_soq523_2X_FV.qt/dbFiles/a108.proto|2012/11/14 15:19:26 | still running |germany|germany

How do we use awk or shell program to get output file B.txt

2012/11/13 20:06:11 | Locations 12, 13, 14, 15|NET12/full_ddr3_2X_FV_4BD_1.qt|norway|norway22
** 22 is first location 12+10 ** Do not include in out put

2012/11/14 14:23:19 |Locations 0, 1, 2, 3, 4, 5, 6, 7 |NET24/full_111_ddr5_soq523_2X_FV.qt|norway|norway10
** 10 is first Locations 0+10 *** Do not include in out put

2012/11/14 14:23:19 |4|  Locations 0, 1 |NET24/full_111_ddr5_soq523_2X_FV.qt|germany|germany10

and an output C.txt tell me that we are missing Locations like

Locations 8, 9, 10, 11|norway|Available
Locations 2,3|germany|Available

* If we see 2nd filed is 16 then location are 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
* If we see 2nd field is 4 then location only 0,1,2,3

Thanks for your reply.

Try these 2:

awk -F\| '{
  sub(/.*Locations /,"",$3)
  path=val=$3
  sub(/,.*/,"",val)
  val+=10
  sub(/ for.*/,"",$3)
  sub(/.*NET/, "NET",path)
  sub(/\.qt.*/, ".qt",path)
  print $1 FS ($2=="16"?"":$2 FS) " Locations " $3 FS path FS $6 FS $7 val}' A.txt > B.txt
awk -F\| '{
  sub(/.*Locations /,"",$3)
  sub(/ for.*/,"",$3)
  L=$6
  M[L]=$2
  gsub(/, /,"|",$3)
  $0=$3
  for(i=1;i<=NF;i++) H[L,$i]
}
END {
   for(L in M) {
      V=""
      for(i=0;i<M[L];i++) if(!((L SUBSEP i) in H)) V=V", "i
      if(length(V)) print "Locations " substr(V,3) "|" L "|Available"
   }
}' A.txt > C.txt

From

awk -F\| '{
  sub(/.*Locations /,"",$3)
  path=val=$3
  sub(/,.*/,"",val)
  val+=10
  sub(/ for.*/,"",$3)
  sub(/.*NET/, "NET",path)
  sub(/\.qt.*/, ".qt",path)
  print $1 FS ($2=="16"?"":$2 FS) " Locations " $3 FS path FS $6 FS $7 val}' A.txt > B.t

I got the result

2012/11/13 20:06:11 ||Locations 12, 13, 14, 15|NET12/full_ddr3_2X_FV_4BD_1.qt|norway|norway22
2012/11/14 14:23:19 ||Locations 0, 1, 2, 3, 4, 5, 6, 7|NET24/full_111_ddr5_soq523_2X_FV.qt|norway|norway10
2012/11/14 14:23:19 |4||Locations 0, 1|NET24/full_111_ddr5_soq523_2X_FV.qt|germany|germany10

and from

awk -F\| '{
  sub(/.*Locations /,"",$3)
  sub(/ for.*/,"",$3)
  L=$6
  M[L]=$2
  gsub(/, /,"|",$3)
  $0=$3
  for(i=1;i<=NF;i++) H[L,$i]
}
END {
   for(L in M) {
      V=""
      for(i=0;i<M[L];i++) if(!((L SUBSEP i) in H)) V=V", "i
      if(length(V)) print "Locations " substr(V,3) "|" L "|Available"
   }
}' A.txt > C.txt

I got the result what i dont expect

Locations 0, 1, 2, 3|germany|Available
Locations 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15|norway|Available

I should see

Locations 2,3|germany|Available
Locations 8, 9, 10, 11|norway|Available

Anyway look like it is hard to get the available locations
My last wish if you have the A.txt like this

2012/11/13 20:06:11 |284:hawk   pid=014268 opened Locations 12, 13, 14, 15 for /home/hawk_t112/t112/macteam/qt/NET12/full_ddr3_2X_FV_4BD_1.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|16|norway
2012/11/14 14:23:19 |288:hawk   pid=019275 opened Locations 0, 1, 2, 3, 4, 5, 6, 7 for /home/hawk_a108/a108/macteam/qt/NET24/full_111_ddr5_soq523_2X_FV.qt/dbFiles/a108.proto|2012/11/14 15:19:26 | still running |norway|16|norway
2012/11/14 14:23:19 |288:hawk   pid=019275 opened Locations 0, 1 for /home/hawk_a108/a108/macteam/qt/NET24/full_111_ddr5_soq523_2X_FV.qt/dbFiles/a108.proto|2012/11/14 15:19:26 | still running |germany|4|germany

Now the 2nd fields was moved to last 2nd fields.
How do i get the result

2012/11/13 20:06:11 |t112|Boards 12, 13, 14, 15|NET12/full_ddr3_2X_FV_4BD_1.qt|norway|norway22
2012/11/14 14:23:19 |t112|Boards 0, 1, 2, 3, 4, 5, 6, 7|NET24/full_111_ddr5_soq523_2X_FV.qt|norway|norway10
2012/11/14 14:23:19 |a108|Boards 0, 1|NET24/full_111_ddr5_soq523_2X_FV.qt|germany|germany10

Thank you so much.

Try

awk -F\| '{
  sub(/.*Locations /,"",$2)
  path=val=$2
  sub(/,.*/,"",val)
  val+=10
  sub(/ for.*/,"",$2)
  sub(/.*for /,"",path)
  split(path, p, "/")
  print $1 FS p[4] FS "Boards " $2 FS p[7] "/" p[8] FS $5 FS $7 val}' A.txt

Works so beautiful. Thanks Chubler_XL