Solution 1 using FINDSTR (native batch commands only)
There is an obscure/undocumented technique using FINDSTR to search across line breaks described at What are the undocumented features and limitations of the Windows FINDSTR command? under the heading "Searching across line breaks". It involves defining a variable to contain a linefeed character, and then including that in the search term.
Assuming you want to post-process the text file (I'll call it test.txt), then you could do something like:
@echo off
setlocal enableDelayedExpansion
:: Define LF to contain a linefeed (0x0A)
set ^"LF=^
^" The above empty line is critical - DO NOT REMOVE
:: Output any line that precedes "Country : UK"
findstr /c:"!LF!Country : UK" test.txt >UK.txt
You could pipe the results of your Active Directory query command to FINDSTR and directly write out the UK results, without an intermediate file. First I'll assume your script does not require delayed expansion. But the FINDSTR does need delayed expansion.
Each side of the pipe is executed in a new cmd.exe session (thread?) with delayed expansion off. FINDSTR must be executed via cmd with the /V:ON argument to turn on delayed expansion:
@echo off
setlocal disableDelayedExpansion
:: Define LF to contain a linefeed (0x0A)
set ^"LF=^
^" The above empty line is critical - DO NOT REMOVE
:: Query Active Directory and only preserve lines that precede "Country : UK"
yourActiveDirectoryCommand|cmd /v:on /c findstr /c:"!LF!Country : UK"
If your script requires delayed expansion, then you still must execute FINIDSTR via cmd and use the /V:ON option, but now you must also escape the delayed expansion so it doesn't expand too early
@echo off
setlocal enableDelayedExpansion
:: Define LF to contain a linefeed (0x0A)
set ^"LF=^
^" The above empty line is critical - DO NOT REMOVE
:: Output any line that precedes "Country : UK"
yourActiveDirectoryCommand|cmd /v:on /c findstr /c:"^!LF^!Country : UK"
Solution 2 using JREPL.BAT (hybrid JScript/batch utility)
JREPL.BAT is a hybrid JScript/batch utility that can easily perform regular expression search and replace across line breaks. It is pure script that runs natively on any Windows machine from XP onward.
You can post-process the file (again, I'm using test.txt)
call jrepl "^([^\r\n]*)\r?\nCountry : UK$" "$1" /jmatch /m /f test.txt /o UK.txt
Or you can pipe your Active Directory query result directly to JREN and avoid the need for an intermediate file:
yourActiveDirectoryCommand|jrepl "^([^\r\n]*)\r?\nCountry : UK$" "$1" /jmatch /m /o UK.txt