Bash使用grep问题解析mongo日志

时间:2018-06-07 06:16:54

标签: bash awk sed grep

我有一个复杂的mongo导入日志来解析。在此日志中,我想选择在“research_database.old_experiment”和“research_database.new_experiment”集合中完成的总导入数。

但导入计数显示在“research_database.old_experiment”的最后一行的下一行& “research_database.new_experiment”以及100%导入时。

#cat console.log
  Started by timer
    [EnvInject] - Loading node environment variables.
    2018-06-06T21:48:31.772-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:31.824-0700    imported 0 documents
    2018-06-06T21:48:31.846-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:31.848-0700    imported 0 documents
    2018-06-06T21:48:31.870-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:31.872-0700    imported 0 documents
    2018-06-06T21:48:31.894-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:31.895-0700    imported 0 documents
    2018-06-06T21:48:31.917-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:31.923-0700    imported 0 documents
    2018-06-06T21:48:31.979-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:31.981-0700    imported 0 documents
    2018-06-06T21:48:32.001-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:32.004-0700    imported 0 documents
    2018-06-06T21:48:32.027-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:32.028-0700    imported 0 documents
    2018-06-06T21:48:32.051-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:32.052-0700    imported 0 documents
    2018-06-06T21:48:32.076-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:32.078-0700    imported 0 documents
    2018-06-06T21:48:32.103-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:32.140-0700    imported 9 documents
    2018-06-06T21:48:32.164-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:32.167-0700    imported 0 documents
    2018-06-06T21:48:32.189-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:48:35.186-0700    [........................] research_database.old_experiment 2.28MB/101MB (2.3%)
    2018-06-06T21:48:38.186-0700    [........................] research_database.old_experiment 3.51MB/101MB (3.5%)
    2018-06-06T21:48:41.186-0700    [#.......................] research_database.old_experiment 4.85MB/101MB (4.8%)
    2018-06-06T21:48:44.186-0700    [#.......................] research_database.old_experiment 6.22MB/101MB (6.2%)
    2018-06-06T21:48:47.186-0700    [##......................] research_database.old_experiment 10.4MB/101MB (10.3%)
    2018-06-06T21:48:50.186-0700    [##......................] research_database.old_experiment 10.4MB/101MB (10.3%)
    2018-06-06T21:48:53.186-0700    [###.....................] research_database.old_experiment 13.9MB/101MB (13.7%)
    2018-06-06T21:48:56.186-0700    [###.....................] research_database.old_experiment 15.9MB/101MB (15.7%)
    2018-06-06T21:48:59.186-0700    [####....................] research_database.old_experiment 17.9MB/101MB (17.7%)
    2018-06-06T21:49:02.186-0700    [####....................] research_database.old_experiment 17.9MB/101MB (17.7%)
    2018-06-06T21:49:05.186-0700    [####....................] research_database.old_experiment 19.9MB/101MB (19.7%)
    2018-06-06T21:49:08.186-0700    [#####...................] research_database.old_experiment 21.9MB/101MB (21.7%)
    2018-06-06T21:49:11.186-0700    [#####...................] research_database.old_experiment 23.9MB/101MB (23.6%)
    2018-06-06T21:49:14.186-0700    [#####...................] research_database.old_experiment 23.9MB/101MB (23.6%)
    2018-06-06T21:49:17.186-0700    [######..................] research_database.old_experiment 28.3MB/101MB (28.0%)
    2018-06-06T21:49:20.186-0700    [#######.................] research_database.old_experiment 32.3MB/101MB (31.9%)
    2018-06-06T21:49:23.186-0700    [#######.................] research_database.old_experiment 32.3MB/101MB (31.9%)
    2018-06-06T21:49:26.186-0700    [#######.................] research_database.old_experiment 32.3MB/101MB (31.9%)
    2018-06-06T21:49:29.186-0700    [########................] research_database.old_experiment 36.2MB/101MB (35.9%)
    2018-06-06T21:49:32.186-0700    [########................] research_database.old_experiment 36.2MB/101MB (35.9%)
    2018-06-06T21:49:35.186-0700    [############............] research_database.old_experiment 51.5MB/101MB (50.9%)
    2018-06-06T21:49:38.186-0700    [############............] research_database.old_experiment 51.5MB/101MB (50.9%)
    2018-06-06T21:49:41.186-0700    [############............] research_database.old_experiment 51.5MB/101MB (50.9%)
    2018-06-06T21:49:44.186-0700    [############............] research_database.old_experiment 51.5MB/101MB (50.9%)
    2018-06-06T21:49:47.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:49:50.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:49:53.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:49:56.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:49:59.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:50:02.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:50:05.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:50:08.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:50:11.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:50:14.186-0700    [################........] research_database.old_experiment 67.5MB/101MB (66.7%)
    2018-06-06T21:50:17.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:20.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:23.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:26.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:29.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:32.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:35.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:38.186-0700    [###################.....] research_database.old_experiment 83.5MB/101MB (82.6%)
    2018-06-06T21:50:41.186-0700    [#######################.] research_database.old_experiment 98.8MB/101MB (97.8%)
    2018-06-06T21:50:44.186-0700    [#######################.] research_database.old_experiment 98.8MB/101MB (97.8%)
    2018-06-06T21:50:47.186-0700    [#######################.] research_database.old_experiment 98.8MB/101MB (97.8%)
    2018-06-06T21:50:50.186-0700    [#######################.] research_database.old_experiment 98.8MB/101MB (97.8%)
    2018-06-06T21:50:53.186-0700    [#######################.] research_database.old_experiment 98.8MB/101MB (97.8%)
    2018-06-06T21:50:56.186-0700    [#######################.] research_database.old_experiment 98.8MB/101MB (97.8%)
    2018-06-06T21:50:59.186-0700    [########################] research_database.old_experiment 101MB/101MB (100.0%)
    2018-06-06T21:51:02.186-0700    [########################] research_database.old_experiment 101MB/101MB (100.0%)
    2018-06-06T21:51:04.295-0700    [########################] research_database.old_experiment 101MB/101MB (100.0%)
    2018-06-06T21:51:04.295-0700    imported 52753 documents
    2018-06-06T21:51:04.354-0700    connected to: 172.18.54.22:27017
    2018-06-06T21:51:07.351-0700    [........................] research_database.new_experiment 55.4MB/2.53GB (2.1%)
    2018-06-06T21:51:10.351-0700    [........................] research_database.new_experiment 97.3MB/2.53GB (3.8%)
    2018-06-06T21:51:13.351-0700    [#.......................] research_database.new_experiment 109MB/2.53GB (4.2%)
    2018-06-06T21:51:16.351-0700    [#.......................] research_database.new_experiment 121MB/2.53GB (4.7%)
    2018-06-06T21:51:19.351-0700    [#.......................] research_database.new_experiment 132MB/2.53GB (5.1%)
    2018-06-06T21:51:22.351-0700    [#.......................] research_database.new_experiment 148MB/2.53GB (5.7%)
    2018-06-06T21:51:25.352-0700    [#.......................] research_database.new_experiment 164MB/2.53GB (6.3%)
    2018-06-06T21:51:28.351-0700    [#.......................] research_database.new_experiment 175MB/2.53GB (6.8%)
    2018-06-06T21:51:31.352-0700    [#.......................] research_database.new_experiment 191MB/2.53GB (7.4%)
    2018-06-06T21:51:34.351-0700    [#.......................] research_database.new_experiment 206MB/2.53GB (8.0%)
    2018-06-06T21:51:37.351-0700    [##......................] research_database.new_experiment 218MB/2.53GB (8.4%)
    2018-06-06T21:51:40.351-0700    [##......................] research_database.new_experiment 234MB/2.53GB (9.1%)
    2018-06-06T21:51:43.351-0700    [##......................] research_database.new_experiment 246MB/2.53GB (9.5%)
    2018-06-06T21:51:46.351-0700    [##......................] research_database.new_experiment 266MB/2.53GB (10.3%)
    2018-06-06T21:51:49.351-0700    [##......................] research_database.new_experiment 282MB/2.53GB (10.9%)
    2018-06-06T21:51:52.352-0700    [##......................] research_database.new_experiment 294MB/2.53GB (11.3%)
    2018-06-06T21:51:55.352-0700    [##......................] research_database.new_experiment 308MB/2.53GB (11.9%)
    2018-06-06T21:51:58.351-0700    [###.....................] research_database.new_experiment 345MB/2.53GB (13.3%)
    2018-06-06T21:52:01.352-0700    [###.....................] research_database.new_experiment 361MB/2.53GB (13.9%)
    2018-06-06T21:52:04.352-0700    [###.....................] research_database.new_experiment 361MB/2.53GB (13.9%)
    2018-06-06T21:52:07.351-0700    [###.....................] research_database.new_experiment 377MB/2.53GB (14.6%)
    2018-06-06T21:52:10.351-0700    [###.....................] research_database.new_experiment 393MB/2.53GB (15.2%)
    2018-06-06T21:52:13.351-0700    [###.....................] research_database.new_experiment 409MB/2.53GB (15.8%)
    2018-06-06T21:52:16.352-0700    [###.....................] research_database.new_experiment 425MB/2.53GB (16.4%)
    2018-06-06T21:52:19.352-0700    [###.....................] research_database.new_experiment 425MB/2.53GB (16.4%)
    2018-06-06T21:52:22.351-0700    [####....................] research_database.new_experiment 440MB/2.53GB (17.0%)
    2018-06-06T21:52:25.352-0700    [####....................] research_database.new_experiment 472MB/2.53GB (18.2%)
    2018-06-06T21:52:28.352-0700    [####....................] research_database.new_experiment 488MB/2.53GB (18.8%)
    2018-06-06T21:52:31.352-0700    [####....................] research_database.new_experiment 504MB/2.53GB (19.5%)
    2018-06-06T21:52:34.351-0700    [####....................] research_database.new_experiment 520MB/2.53GB (20.1%)
    2018-06-06T21:52:37.351-0700    [#####...................] research_database.new_experiment 552MB/2.53GB (21.3%)
    2018-06-06T21:52:40.351-0700    [#####...................] research_database.new_experiment 567MB/2.53GB (21.9%)
    2018-06-06T21:52:43.351-0700    [#####...................] research_database.new_experiment 567MB/2.53GB (21.9%)
    2018-06-06T21:52:46.351-0700    [#####...................] research_database.new_experiment 583MB/2.53GB (22.5%)
    2018-06-06T21:52:49.351-0700    [#####...................] research_database.new_experiment 599MB/2.53GB (23.1%)
    2018-06-06T21:52:52.351-0700    [#####...................] research_database.new_experiment 615MB/2.53GB (23.8%)
    2018-06-06T21:52:55.351-0700    [#####...................] research_database.new_experiment 631MB/2.53GB (24.4%)
    2018-06-06T21:52:58.351-0700    [######..................] research_database.new_experiment 663MB/2.53GB (25.6%)
    2018-06-06T21:53:01.351-0700    [######..................] research_database.new_experiment 679MB/2.53GB (26.2%)
    2018-06-06T21:53:04.351-0700    [######..................] research_database.new_experiment 695MB/2.53GB (26.8%)
    2018-06-06T21:53:07.351-0700    [######..................] research_database.new_experiment 711MB/2.53GB (27.5%)
    2018-06-06T21:53:10.351-0700    [######..................] research_database.new_experiment 711MB/2.53GB (27.5%)
    2018-06-06T21:53:13.351-0700    [######..................] research_database.new_experiment 727MB/2.53GB (28.1%)
    2018-06-06T21:53:16.352-0700    [#######.................] research_database.new_experiment 759MB/2.53GB (29.3%)
    2018-06-06T21:53:19.351-0700    [#######.................] research_database.new_experiment 775MB/2.53GB (29.9%)
    2018-06-06T21:53:22.351-0700    [#######.................] research_database.new_experiment 791MB/2.53GB (30.5%)
    2018-06-06T21:53:25.351-0700    [#######.................] research_database.new_experiment 806MB/2.53GB (31.1%)
    2018-06-06T21:53:28.351-0700    [#######.................] research_database.new_experiment 822MB/2.53GB (31.8%)
    2018-06-06T21:53:31.351-0700    [#######.................] research_database.new_experiment 838MB/2.53GB (32.4%)
    2018-06-06T21:53:34.351-0700    [#######.................] research_database.new_experiment 854MB/2.53GB (33.0%)
    2018-06-06T21:53:37.351-0700    [########................] research_database.new_experiment 870MB/2.53GB (33.6%)
    2018-06-06T21:53:40.351-0700    [########................] research_database.new_experiment 886MB/2.53GB (34.2%)
    2018-06-06T21:53:43.351-0700    [########................] research_database.new_experiment 902MB/2.53GB (34.8%)
    2018-06-06T21:53:46.351-0700    [########................] research_database.new_experiment 902MB/2.53GB (34.8%)
    2018-06-06T21:53:49.351-0700    [########................] research_database.new_experiment 934MB/2.53GB (36.1%)
    2018-06-06T21:53:52.352-0700    [########................] research_database.new_experiment 950MB/2.53GB (36.7%)
    2018-06-06T21:53:55.352-0700    [########................] research_database.new_experiment 950MB/2.53GB (36.7%)
    2018-06-06T21:53:58.351-0700    [########................] research_database.new_experiment 966MB/2.53GB (37.3%)
    2018-06-06T21:54:01.351-0700    [#########...............] research_database.new_experiment 997MB/2.53GB (38.5%)
    2018-06-06T21:54:04.351-0700    [#########...............] research_database.new_experiment 1013MB/2.53GB (39.1%)
    2018-06-06T21:54:07.351-0700    [#########...............] research_database.new_experiment 1.01GB/2.53GB (39.8%)
    2018-06-06T21:54:10.351-0700    [#########...............] research_database.new_experiment 1.04GB/2.53GB (40.9%)
    2018-06-06T21:54:13.351-0700    [#########...............] research_database.new_experiment 1.05GB/2.53GB (41.4%)
    2018-06-06T21:54:16.351-0700    [##########..............] research_database.new_experiment 1.08GB/2.53GB (42.6%)
    2018-06-06T21:54:19.352-0700    [##########..............] research_database.new_experiment 1.09GB/2.53GB (43.3%)
    2018-06-06T21:54:22.351-0700    [##########..............] research_database.new_experiment 1.11GB/2.53GB (43.9%)
    2018-06-06T21:54:25.351-0700    [##########..............] research_database.new_experiment 1.13GB/2.53GB (44.5%)
    2018-06-06T21:54:28.351-0700    [##########..............] research_database.new_experiment 1.14GB/2.53GB (45.1%)
    2018-06-06T21:54:31.351-0700    [###########.............] research_database.new_experiment 1.17GB/2.53GB (46.3%)
    2018-06-06T21:54:34.352-0700    [###########.............] research_database.new_experiment 1.19GB/2.53GB (46.9%)
    2018-06-06T21:54:37.352-0700    [###########.............] research_database.new_experiment 1.21GB/2.53GB (47.9%)
    2018-06-06T21:54:40.352-0700    [###########.............] research_database.new_experiment 1.23GB/2.53GB (48.5%)
    2018-06-06T21:54:43.351-0700    [###########.............] research_database.new_experiment 1.24GB/2.53GB (49.2%)
    2018-06-06T21:54:46.351-0700    [###########.............] research_database.new_experiment 1.24GB/2.53GB (49.2%)
    2018-06-06T21:54:49.351-0700    [###########.............] research_database.new_experiment 1.26GB/2.53GB (49.8%)
    2018-06-06T21:54:52.352-0700    [############............] research_database.new_experiment 1.27GB/2.53GB (50.4%)
    2018-06-06T21:54:55.352-0700    [############............] research_database.new_experiment 1.29GB/2.53GB (51.0%)
    2018-06-06T21:54:58.351-0700    [############............] research_database.new_experiment 1.30GB/2.53GB (51.6%)
    2018-06-06T21:55:01.352-0700    [############............] research_database.new_experiment 1.32GB/2.53GB (52.2%)
    2018-06-06T21:55:04.351-0700    [############............] research_database.new_experiment 1.34GB/2.53GB (52.8%)
    2018-06-06T21:55:07.351-0700    [############............] research_database.new_experiment 1.35GB/2.53GB (53.4%)
    2018-06-06T21:55:10.351-0700    [#############...........] research_database.new_experiment 1.38GB/2.53GB (54.6%)
    2018-06-06T21:55:13.351-0700    [#############...........] research_database.new_experiment 1.41GB/2.53GB (55.8%)
    2018-06-06T21:55:16.352-0700    [#############...........] research_database.new_experiment 1.44GB/2.53GB (56.8%)
    2018-06-06T21:55:19.352-0700    [#############...........] research_database.new_experiment 1.45GB/2.53GB (57.5%)
    2018-06-06T21:55:22.352-0700    [#############...........] research_database.new_experiment 1.45GB/2.53GB (57.5%)
    2018-06-06T21:55:25.351-0700    [#############...........] research_database.new_experiment 1.47GB/2.53GB (58.1%)
    2018-06-06T21:55:28.352-0700    [##############..........] research_database.new_experiment 1.50GB/2.53GB (59.3%)
    2018-06-06T21:55:31.351-0700    [##############..........] research_database.new_experiment 1.52GB/2.53GB (59.9%)
    2018-06-06T21:55:34.352-0700    [##############..........] research_database.new_experiment 1.53GB/2.53GB (60.5%)
    2018-06-06T21:55:37.351-0700    [##############..........] research_database.new_experiment 1.56GB/2.53GB (61.8%)
    2018-06-06T21:55:40.351-0700    [##############..........] research_database.new_experiment 1.58GB/2.53GB (62.4%)
    2018-06-06T21:55:43.351-0700    [###############.........] research_database.new_experiment 1.60GB/2.53GB (63.4%)
    2018-06-06T21:55:46.351-0700    [###############.........] research_database.new_experiment 1.62GB/2.53GB (64.0%)
    2018-06-06T21:55:49.351-0700    [###############.........] research_database.new_experiment 1.63GB/2.53GB (64.6%)
    2018-06-06T21:55:52.351-0700    [###############.........] research_database.new_experiment 1.65GB/2.53GB (65.2%)
    2018-06-06T21:55:55.351-0700    [###############.........] research_database.new_experiment 1.67GB/2.53GB (65.9%)
    2018-06-06T21:55:58.351-0700    [################........] research_database.new_experiment 1.71GB/2.53GB (67.7%)
    2018-06-06T21:56:01.351-0700    [################........] research_database.new_experiment 1.74GB/2.53GB (68.9%)
    2018-06-06T21:56:04.351-0700    [################........] research_database.new_experiment 1.76GB/2.53GB (69.5%)
    2018-06-06T21:56:07.351-0700    [################........] research_database.new_experiment 1.77GB/2.53GB (70.1%)
    2018-06-06T21:56:10.351-0700    [################........] research_database.new_experiment 1.79GB/2.53GB (70.7%)
    2018-06-06T21:56:13.351-0700    [#################.......] research_database.new_experiment 1.80GB/2.53GB (71.3%)
    2018-06-06T21:56:16.351-0700    [#################.......] research_database.new_experiment 1.82GB/2.53GB (71.9%)
    2018-06-06T21:56:19.351-0700    [#################.......] research_database.new_experiment 1.82GB/2.53GB (71.9%)
    2018-06-06T21:56:22.351-0700    [#################.......] research_database.new_experiment 1.85GB/2.53GB (73.1%)
    2018-06-06T21:56:25.351-0700    [#################.......] research_database.new_experiment 1.86GB/2.53GB (73.7%)
    2018-06-06T21:56:28.351-0700    [#################.......] research_database.new_experiment 1.88GB/2.53GB (74.4%)
    2018-06-06T21:56:31.351-0700    [#################.......] research_database.new_experiment 1.90GB/2.53GB (75.0%)
    2018-06-06T21:56:34.351-0700    [##################......] research_database.new_experiment 1.91GB/2.53GB (75.6%)
    2018-06-06T21:56:37.351-0700    [##################......] research_database.new_experiment 1.93GB/2.53GB (76.2%)
    2018-06-06T21:56:40.351-0700    [##################......] research_database.new_experiment 1.94GB/2.53GB (76.8%)
    2018-06-06T21:56:43.351-0700    [##################......] research_database.new_experiment 1.96GB/2.53GB (77.4%)
    2018-06-06T21:56:46.351-0700    [##################......] research_database.new_experiment 1.97GB/2.53GB (78.0%)
    2018-06-06T21:56:49.351-0700    [##################......] research_database.new_experiment 1.99GB/2.53GB (78.7%)
    2018-06-06T21:56:52.351-0700    [###################.....] research_database.new_experiment 2.00GB/2.53GB (79.3%)
    2018-06-06T21:56:55.351-0700    [###################.....] research_database.new_experiment 2.03GB/2.53GB (80.5%)
    2018-06-06T21:56:58.351-0700    [###################.....] research_database.new_experiment 2.03GB/2.53GB (80.5%)
    2018-06-06T21:57:01.351-0700    [###################.....] research_database.new_experiment 2.05GB/2.53GB (81.1%)
    2018-06-06T21:57:04.351-0700    [###################.....] research_database.new_experiment 2.08GB/2.53GB (82.3%)
    2018-06-06T21:57:07.351-0700    [###################.....] research_database.new_experiment 2.10GB/2.53GB (82.9%)
    2018-06-06T21:57:10.351-0700    [####################....] research_database.new_experiment 2.11GB/2.53GB (83.5%)
    2018-06-06T21:57:13.351-0700    [####################....] research_database.new_experiment 2.11GB/2.53GB (83.5%)
    2018-06-06T21:57:16.351-0700    [####################....] research_database.new_experiment 2.13GB/2.53GB (84.1%)
    2018-06-06T21:57:19.351-0700    [####################....] research_database.new_experiment 2.14GB/2.53GB (84.8%)
    2018-06-06T21:57:22.351-0700    [####################....] research_database.new_experiment 2.17GB/2.53GB (85.9%)
    2018-06-06T21:57:25.351-0700    [####################....] research_database.new_experiment 2.19GB/2.53GB (86.5%)
    2018-06-06T21:57:28.351-0700    [####################....] research_database.new_experiment 2.19GB/2.53GB (86.5%)
    2018-06-06T21:57:31.351-0700    [####################....] research_database.new_experiment 2.20GB/2.53GB (87.2%)
    2018-06-06T21:57:34.351-0700    [#####################...] research_database.new_experiment 2.22GB/2.53GB (87.8%)
    2018-06-06T21:57:37.351-0700    [#####################...] research_database.new_experiment 2.23GB/2.53GB (88.4%)
    2018-06-06T21:57:40.351-0700    [#####################...] research_database.new_experiment 2.27GB/2.53GB (89.6%)
    2018-06-06T21:57:43.351-0700    [#####################...] research_database.new_experiment 2.27GB/2.53GB (89.6%)
    2018-06-06T21:57:46.351-0700    [#####################...] research_database.new_experiment 2.28GB/2.53GB (90.2%)
    2018-06-06T21:57:49.351-0700    [#####################...] research_database.new_experiment 2.30GB/2.53GB (90.8%)
    2018-06-06T21:57:52.351-0700    [#####################...] research_database.new_experiment 2.31GB/2.53GB (91.5%)
    2018-06-06T21:57:55.351-0700    [######################..] research_database.new_experiment 2.33GB/2.53GB (92.1%)
    2018-06-06T21:57:58.351-0700    [######################..] research_database.new_experiment 2.34GB/2.53GB (92.7%)
    2018-06-06T21:58:01.351-0700    [######################..] research_database.new_experiment 2.36GB/2.53GB (93.3%)
    2018-06-06T21:58:04.351-0700    [######################..] research_database.new_experiment 2.37GB/2.53GB (93.9%)
    2018-06-06T21:58:07.351-0700    [######################..] research_database.new_experiment 2.39GB/2.53GB (94.5%)
    2018-06-06T21:58:10.351-0700    [######################..] research_database.new_experiment 2.41GB/2.53GB (95.1%)
    2018-06-06T21:58:13.351-0700    [######################..] research_database.new_experiment 2.42GB/2.53GB (95.8%)
    2018-06-06T21:58:16.351-0700    [#######################.] research_database.new_experiment 2.44GB/2.53GB (96.4%)
    2018-06-06T21:58:19.351-0700    [#######################.] research_database.new_experiment 2.45GB/2.53GB (97.0%)
    2018-06-06T21:58:22.351-0700    [#######################.] research_database.new_experiment 2.47GB/2.53GB (97.6%)
    2018-06-06T21:58:25.351-0700    [#######################.] research_database.new_experiment 2.48GB/2.53GB (98.2%)
    2018-06-06T21:58:28.351-0700    [#######################.] research_database.new_experiment 2.48GB/2.53GB (98.2%)
    2018-06-06T21:58:31.352-0700    [#######################.] research_database.new_experiment 2.51GB/2.53GB (99.4%)
    2018-06-06T21:58:34.351-0700    [#######################.] research_database.new_experiment 2.51GB/2.53GB (99.4%)
    2018-06-06T21:58:37.351-0700    [########################] research_database.new_experiment 2.53GB/2.53GB (100.0%)
    2018-06-06T21:58:40.351-0700    [########################] research_database.new_experiment 2.53GB/2.53GB (100.0%)
    2018-06-06T21:58:42.737-0700    [########################] research_database.new_experiment 2.53GB/2.53GB (100.0%)
    2018-06-06T21:58:42.737-0700    imported 83116 documents
    Processing archive : research_migration_20180607_0426.tgz
    Processing exported file : ./research_migration_20180607_0426_old_experiment.json
    Processing exported file : ./research_migration_20180607_0426_new_experiment.json
    Started calculate disk usage of build
    Finished Calculation of disk usage of build in 0 seconds
    Started calculate disk usage of workspace
    Finished Calculation of disk usage of workspace in 0 seconds
    Finished: SUCCESS

此处“research_database.old_experiment”的导入记录为“52753”,“research_database.new_experiment”的导入记录为“83116”。

我试图grep for the line

$ grep "research_database.old_experiment" console.log | grep "100.0%"

2018-06-06T21:50:59.186-0700    [########################] research_database.old_experiment 101MB/101MB (100.0%)
2018-06-06T21:51:02.186-0700    [########################] research_database.old_experiment 101MB/101MB (100.0%)
2018-06-06T21:51:04.295-0700    [########################] research_database.old_experiment 101MB/101MB (100.0%)

我不确定如何从上面的imported <> documents以及research_database.new_experiment模式grep中获取总grep行?有什么建议吗?

1 个答案:

答案 0 :(得分:2)

您可以使用以下awk脚本:

awk '/\[[.#]+\]/{n=$3} n&&/documents$/{print n,$3;n=""}' file

变量n包含导入的名称。如果已设置并且找到包含documents的行,则会打印导入的文档数。