Hi sagar_1986,
Note that we are ignoring the second issue you raised in message #3 in this thread. We don't need to discuss one issue in two threads; it makes it much too hard for the volunteers trying to help you if you discuss the same issue in two places.
Note that SriniShoo's script will not print the "00" line if it isn't present in the input file. Assuming that the input file is sorted by hour, this seems to do what SriniShoo was trying to do:
awk -F'[.]' '
NR == 1 {
t = substr($1,5)
a = 0
}
{ b = substr($1, 3, 2)
for(i = a; i < b + 0; i++)
printf("%02d%d\n", i, t)
a = b + 1
}
END { for(i = a; i <= 23; i++)
printf("%02d%d\n", i, t)
}' file
If I were going to try this using bharat1211's approach (which would be required if the input is not sorted), I would simplify it to something more like:
awk -F'[.]' '
FNR == 1 {
t = substr($1, 5)
}
{ h[substr($1, 3, 2)]
}
END { for(i = 0; i < 24; i++)
if(!((hour = sprintf("%02d", i)) in h))
print hour t
}' file
If file
contains:
df01231587.dat
df03231587.dat
df04231587.dat
df06231587.dat
df07231587.dat
df08231587.dat
df09231587.dat
df10231587.dat
df11231587.dat
df12231587.dat
df13231587.dat
df14231587.dat
df16231587.dat
df17231587.dat
df18231587.dat
df19231587.dat
df22231587.dat
both of these scripts produce the output:
00231587
02231587
05231587
15231587
20231587
21231587
23231587
For any readers who want to try this on a Solaris/SunOS system, change awk
to /usr/xpg4/bin/awk
, /usr/xpg6/bin/awk
, or nawk
.