I have a file “capinfos.txt” which contains:
[file]
pcap0000.pcap
Thu Feb 10 15:58:48 2011
Thu Feb 10 19:27:26 2011
pcap0001.pcap
Thu Feb 10 19:27:26 2011
Thu Feb 10 20:35:35 2011
pcap0002.pcap
Thu Feb 10 20:35:35 2011
Mon Feb 14 11:10:43 2011
pcap0003.pcap
Mon Feb 14 11:10:43 2011
Mon Feb 14 12:25:11 2011
pcap0004.pcap
Mon Feb 14 12:25:11 2011
Mon Feb 14 14:31:13 2011
pcap0005.pcap
Mon Feb 14 14:31:13 2011
Mon Feb 14 22:34:23 2011
pcap0006.pcap
Mon Feb 14 22:34:23 2011
Tue Feb 15 11:21:04 2011
pcap0007.pcap
Tue Feb 15 11:21:04 2011
Tue Feb 15 11:33:34 2011
pcap0008.pcap
Tue Feb 15 11:33:34 2011
Tue Feb 15 12:31:50 2011
pcap0009.pcap
Tue Feb 15 12:31:50 2011
Tue Feb 15 12:51:50 2011
pcap0010.pcap
Tue Feb 15 12:51:50 2011
Tue Feb 15 13:25:03 2011
pcap0011.pcap
Tue Feb 15 13:25:03 2011
Tue Feb 15 14:15:05 2011
pcap0012.pcap
Tue Feb 15 14:15:05 2011
Tue Feb 15 14:37:02 2011
pcap0013.pcap
Tue Feb 15 14:37:02 2011
Tue Feb 15 15:18:09 2011
pcap0014.pcap
Tue Feb 15 15:18:09 2011
Tue Feb 15 17:27:15 2011
pcap0015.pcap
Tue Feb 15 17:27:15 2011
Wed Feb 16 13:10:12 2011
pcap0016.pcap
Wed Feb 16 13:10:12 2011
Wed Feb 16 16:03:18 2011
pcap0017.pcap
Wed Feb 16 16:03:18 2011
Thu Feb 17 13:32:06 2011
pcap0018.pcap
Thu Feb 17 13:32:06 2011
Thu Feb 17 19:33:41 2011
pcap0019.pcap
Thu Feb 17 19:33:41 2011
Thu Feb 17 19:38:45 2011
pcap0020.pcap
Thu Feb 17 19:38:45 2011
Thu Feb 17 23:37:42 2011
pcap0021.pcap
Thu Feb 17 23:37:42 2011
Sun Feb 20 11:50:00 2011
[/file]
After running the following, I end up with a file called “count.txt”
By running the following for each date I can determine the starting file name for each date:
I know that “Feb 14” files start with “pcap0002.pcap” and I know from the “uniq -c” in count.txt that “Feb 14” includes 4 files. How can I update count.txt to show the start and end file names for each date? Basically, I think it would be something like:
All said and done count.txt would ideally look like this:
[file]
Feb 10 pcap0000.pcap pcap0002.pcap
Feb 14 pcap0002.pcap pcap0006.pcap
Feb 15 pcap0006.pcap pcap0015.pcap
Feb 16 pcap0015.pcap pcap0017.pcap
Feb 17 pcap0017.pcap pcap0021.pcap
[/file]
Any help is greatly appreciated!
[file]
pcap0000.pcap
Thu Feb 10 15:58:48 2011
Thu Feb 10 19:27:26 2011
pcap0001.pcap
Thu Feb 10 19:27:26 2011
Thu Feb 10 20:35:35 2011
pcap0002.pcap
Thu Feb 10 20:35:35 2011
Mon Feb 14 11:10:43 2011
pcap0003.pcap
Mon Feb 14 11:10:43 2011
Mon Feb 14 12:25:11 2011
pcap0004.pcap
Mon Feb 14 12:25:11 2011
Mon Feb 14 14:31:13 2011
pcap0005.pcap
Mon Feb 14 14:31:13 2011
Mon Feb 14 22:34:23 2011
pcap0006.pcap
Mon Feb 14 22:34:23 2011
Tue Feb 15 11:21:04 2011
pcap0007.pcap
Tue Feb 15 11:21:04 2011
Tue Feb 15 11:33:34 2011
pcap0008.pcap
Tue Feb 15 11:33:34 2011
Tue Feb 15 12:31:50 2011
pcap0009.pcap
Tue Feb 15 12:31:50 2011
Tue Feb 15 12:51:50 2011
pcap0010.pcap
Tue Feb 15 12:51:50 2011
Tue Feb 15 13:25:03 2011
pcap0011.pcap
Tue Feb 15 13:25:03 2011
Tue Feb 15 14:15:05 2011
pcap0012.pcap
Tue Feb 15 14:15:05 2011
Tue Feb 15 14:37:02 2011
pcap0013.pcap
Tue Feb 15 14:37:02 2011
Tue Feb 15 15:18:09 2011
pcap0014.pcap
Tue Feb 15 15:18:09 2011
Tue Feb 15 17:27:15 2011
pcap0015.pcap
Tue Feb 15 17:27:15 2011
Wed Feb 16 13:10:12 2011
pcap0016.pcap
Wed Feb 16 13:10:12 2011
Wed Feb 16 16:03:18 2011
pcap0017.pcap
Wed Feb 16 16:03:18 2011
Thu Feb 17 13:32:06 2011
pcap0018.pcap
Thu Feb 17 13:32:06 2011
Thu Feb 17 19:33:41 2011
pcap0019.pcap
Thu Feb 17 19:33:41 2011
Thu Feb 17 19:38:45 2011
pcap0020.pcap
Thu Feb 17 19:38:45 2011
Thu Feb 17 23:37:42 2011
pcap0021.pcap
Thu Feb 17 23:37:42 2011
Sun Feb 20 11:50:00 2011
[/file]
After running the following, I end up with a file called “count.txt”
Code:
gawk '2==NR%3 {print $2" "$3}' capinfos.txt|uniq -c > count.txt; gawk 'END{print $2" "$3}' capinfos.txt|uniq -c >> count.txt
cat count.txt
Returns:
3 Feb 10
4 Feb 14
9 Feb 15
2 Feb 16
4 Feb 17
By running the following for each date I can determine the starting file name for each date:
Code:
grep -B 2 "Feb 14" capinfos.txt|head -1
Returns:
pcap0002.pcap
I know that “Feb 14” files start with “pcap0002.pcap” and I know from the “uniq -c” in count.txt that “Feb 14” includes 4 files. How can I update count.txt to show the start and end file names for each date? Basically, I think it would be something like:
Code:
pseudo code:
in a for loop...
set the file count in count.txt for “Feb 14” as a variable, i.e. FCOUNT in this case =”4” as well as the date... CDATE=First date ++1
grep -B 2 $CDATE capinfos.txt|head -1|gawk '{print $1" pcap"(0002 + $FCOUNT)}'
Hopefully producing “pcap0002.pcap pcap0006.pcap
”
then strip out the file count and append the new data to the date in count.txt
All said and done count.txt would ideally look like this:
[file]
Feb 10 pcap0000.pcap pcap0002.pcap
Feb 14 pcap0002.pcap pcap0006.pcap
Feb 15 pcap0006.pcap pcap0015.pcap
Feb 16 pcap0015.pcap pcap0017.pcap
Feb 17 pcap0017.pcap pcap0021.pcap
[/file]
Any help is greatly appreciated!