1

I want to only output certain lines from a command result into another file.
This is my script

@echo off
del "C:\Users\admin\Desktop\script1results.txt"

cd C:\Users\ndujakov\DIG
for /f %%a in (C:\Users\admin\Desktop\script1inputs.txt) do (
dig %%a >> C:\Users\admin\Desktop\script1results.txt
) 

Here are the results and what I want to specifically output

; <<>> DiG 9.10.6-P1 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6710
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com.            IN  A

;; ANSWER SECTION:
google.com.     248 IN  A   172.217.160.206    <---This one

;; Query time: 1 msec                          <---This one
;; SERVER: 10.231.0.106#53(10.231.0.106)
;; WHEN: Fri Feb 02 08:25:55 Pacific Standard Time 2018
;; MSG SIZE  rcvd: 55
2
  • 2
    how to decide, which lines? Commented Feb 2, 2018 at 16:47
  • 1
    Open a command prompt window and run findstr /? for help on this command. You can specify multiple search strings which are OR interpreted to get a filtered output written into a file. Commented Feb 2, 2018 at 17:31

1 Answer 1

1

You can get started with this batch file to filter your results :

@echo off
set "Inputfile=result.txt"
set "TmpFile=%Tmp%\%random%.txt"
set "OutPutFile=FilterResult.txt"
(FindStr /IR /C:"[0-9].[0-9].[0-9].[0-9]" /C:"msec" "%inputfile%")>"%TmpFile%"
(Findstr /IV "server" "%TmpFile%")>"%OutPutFile%"
Start "" "%OutPutFile%" & del "%TmpFile%"

Further Reading

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.