-5

I need to print outs of cert file blocks one by one

---BEGIN---
AA
BB
CC
--END CERTIFICATE---
--BEGIN---
AA
BB
CC
--END CERTIFICATE--

would need out put for running in a loop some thing like

for i in block
do
echo block ( first begin/end certificate block)
echo "==============================="
done
3
  • 3
    Can you please provide example of expected output? Commented Dec 21, 2024 at 20:31
  • 4
    Also, what operating system are you using so we know what tools are available. What have you tried and how did it fail? What exactly is the input, and what is the expected output? We can't help if you don't tell us what you are doing. Commented Dec 21, 2024 at 21:36
  • 1
    also of interest will be your real requirement; does your real world requirement consist solely of reprinting data to stdout (with additional "==============" lines)? or do you need to do something else with each certificate block within the for loop? Commented Dec 21, 2024 at 21:45

1 Answer 1

1

Here is a simple one liner that seems to fit the bill, assuming the certificate blocks of interest are everything between "BEGIN" and "END CERTIFICATE":

> awk '$0 ~ "BEGIN" {next}; $0 ~ "END CERTIFICATE" {flag="END";print "============================";next} 1' data.txt
AA
BB
CC
============================
AA
BB
CC
============================

with:

> cat data.txt
---BEGIN---
AA
BB
CC
--END CERTIFICATE---
--BEGIN---
AA
BB
CC
--END CERTIFICATE--
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.