I'd like to print router configuration and sort only lines starting with pattern crypto isakmp key 6
.
The important thing is that I want to leave that lines in same place so all lines before and after these lines should stay in same place and order (not sorted).
Example input file:
123 345
678 901
bla bla bla
ble ble ble
crypto isakmp key 6 kokofeofepokpfowkfpwjeiofjwiojefiow address 123.456.789.012
crypto isakmp key 6 ofjwiojefiow352okdwofkwkfi9i42kpfsej09f09j4 address 123.456.789.012
crypto isakmp key 6 9i42kpfsej09f09j4ofjwiojefiow352okdwofkwkfi address 123.456.789.012
crypto isakmp key 6 9j4ofjwiojefiow352okdwofkwkfi9i42kpfsej09f0 address 123.456.789.012
ccc ddd eee
fff ggg hhh iii
123 456
So first I'd like to print unchanged ( random count of rows ):
123 345
678 901
bla bla bla
ble ble ble
Then I want to print SORTED lines starting with crypto isakmp key 6.
At the end I'd like to print rest of file unchanged (also random count of rows):
ccc ddd eee
fff ggg hhh iii
123 456
I've managed this by many operations including getting first and last position of crypto isakmp key 6
and using tail
/ head
commands but it's quite complicated and I wonder if there is option in AWK/SED maybe other linux tool to manage it for specified lines. Please explain what your command does in steps.
Expected output (crypto sorted rest intact):
123 345
678 901
bla bla bla
ble ble ble
crypto isakmp key 6 9i42kpfsej09f09j4ofjwiojefiow352okdwofkwkfi address 123.456.789.012
crypto isakmp key 6 9j4ofjwiojefiow352okdwofkwkfi9i42kpfsej09f0 address 123.456.789.012
crypto isakmp key 6 kokofeofepokpfowkfpwjeiofjwiojefiow address 123.456.789.012
crypto isakmp key 6 ofjwiojefiow352okdwofkwkfi9i42kpfsej09f09j4 address 123.456.789.012
ccc ddd eee
fff ggg hhh iii
123 456