Quick Linux Tip #43:
Try: sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' /etc/ssl/certs/server.crt
Info: sed -n suppresses automatic printing. The pattern '/START/,/END/p' prints all lines between two matching delimiters (inclusive).
Examples:
- $ sed -n '/^\[database\]/,/^$/p' config.ini # Extract section until empty line
- $ awk '/BEGIN/,/END/' file.txt # Equivalent using awk
- $ sed -n '/ERROR/,+5p' logfile # Print ERROR line plus next 5 lines
Note: Range matching /X/,/Y/ works line-by-line from first match of X to next match of Y. The +N relative line count syntax is a GNU sed extension.
Leave a Reply