Я хочу извлечь следующее содержимое между The SUMMARY
и End processing summary for first university
, а также The SUMMARY
и End processing summary for second university
Это мой файл:
Logs here
...
...
...
More logs here
...
...
The SUMMARY
Total students: 1200
Total teachers: 10
Total subjects: 20
Total attendance: 12000
End processing summary for first university
Logs here
...
...
...
More logs here
...
...
The SUMMARY
Total students: 1500
Total teachers: 12
Total subjects: 15
Total attendance: 20000
End processing summary for second university
Logs here
...
...
...
More logs here
...
...
следующие работы прекрасно работают:
firstUniversity=$(awk '/The SUMMARY/ && ++n == 1, /End processing summary for first university/' < theLog.log)
secondUniversity=$(awk '/The SUMMARY/ && ++n == 2, /End processing summary for second university/' < theLog.log)
Однако , иногда либо the summary for first university
, либо the summary for second university
отсутствует, и приведенный выше код не работает.
Первый отсутствует университетский блок
Logs here
...
...
...
More logs here
...
...
Logs here
...
...
...
More logs here
...
...
The SUMMARY
Total students: 1500
Total teachers: 12
Total subjects: 15
Total attendance: 20000
End processing summary for second university
Logs here
...
...
...
More logs here
...
...
или отсутствует второй университетский блок
Logs here
...
...
...
More logs here
...
...
The SUMMARY
Total students: 1200
Total teachers: 10
Total subjects: 20
Total attendance: 12000
End processing summary for first university
Logs here
...
...
...
More logs here
Любое решение, использующее sed
или awk
команды?