M
M
Mon4ik2020-11-26 23:02:42
cmd/bat
Mon4ik, 2020-11-26 23:02:42

cmd. How to use findstr to display multiple lines in a row?

Got a team

certutil F:\\find\\3123.crl | findstr 0178dd6f0071aca5b6474113327488997f

The command looks for the serial number in the list of revoked certificates and returns a string if it is there. The
string is returned:
Serial number: 0178dd6f0071aca5b6474113327488997f

How to make search by serial number return all related rows.
The list itself looks like this:

Serial number: 01410749007EAC8FAD4FAP2A72239FEAFCA1 Date
of review: 25.11.2020 11:09
Expansion: 1
2.5.29.21: Flags = 0, Length Causion
Code (CRL)
Certificate Replaced (4)

Serial Room20
:45
Extensions: 1
2.5.29.21: Flags = 0, Length = 3
Revocation List (CRL) Reason Code
Replaced (4)

Serial Number: 019f296d007eac0ab04dcfeee27373ad6c Revocation
Date: 11/25/2020 9:40 AM
Extensions: 1
2.5.29.21: Flags = 0, Length = 3
Revocation list (CRL) reason code
Certificate replaced (4)

That is, you need to display all the lines until the empty one.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Vasilyev, 2020-11-26
@vasilyevmn

Loop, examples for your question are here:
https://www.cyberforum.ru/cmd-bat/thread786795.html

R
res2001, 2020-11-27
@res2001

If certutil can display data only for a specific certificate from the revocation list, then you can call certutil again with a specific certificate by finding the desired serial number with your command.
Windows is not at hand now, I can not check my assumption.

W
wisgest, 2020-11-27
@wisgest

It can be like this:

@echo off
certutil F:\\find\\3123.crl| find /v /n "">temp.txt
set "str=0178dd6f0071aca5b6474113327488997f"
for /f "delims=[]" %%1 in ('find "%str%"^<temp.txt') do  call :sub %%1
del temp.txt
exit /b

:sub
set /a skip = %1 - 1
for /f "skip=%skip% tokens=1,* delims=]" %%1 in (temp.txt) do (
  echo(%%2
  if "%%2"=="" exit /b
)

(If there are errors with the encoding, try adding the second or third line .) If you wish, you can do it without external utilities or ... chcp 1251>nul
findfindstr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question