В следующей статье объясняется общая процедура возврата / понижения до стандартных версий репозитория пакетов или даже подсистемы, если ваша система становится неустойчивой после установки пакетов из тестирования PPA:
http: // oldpapyrus. wordpress.com/2013/10/20/rescue-ubuntu-from-unstable-ppa-issues/
Вы пытаетесь получить данные, структурированные в форме:
aaa ...
...
...
!
Вам нужно сделать sed осведомленным о том, что элементы с отступом имеют значение. Грубым способом может быть запись цикла в sed:
sed -n '
# Create a label named 'start'
:start
# If the line matches the beginning of a block,
# jump (branch) to the label named section
/aaa accounting exec default/ b section
# If we didn't branch, get the next line
n
# Jump back to the start label
b start
# The label named section
:section
# print the line
p
n
# Keep looping to section for the lines we need
/^ /,/!/ b section
# If we don't have any more lines to loop on,
# jump back to the beginning
b start
'
В одной строке:
$ sed -n ':start; /aaa accounting exec default/ b section; n; b start; :section; p; n; /^ /, /!/ b section; b start' test.txt
aaa accounting exec default start-stop group tacacs+
aaa accounting exec default
action-type start-only
group tacacs+
!
aaa accounting exec default stop-only group tacacs+
Это можно сделать более читаемым способом, используя awk, perl или python, я бы предположил.