1.

Solve : findstr vs. For /f?

Answer»

What should i use to strip a text file like:

X-Secure-ID:XXXXXXXXXXXXXXXXX
X-Secure-Country-Code: US - UNITED STATES
X-Secure-TLS-SUITE-INCOMING: XXXXXXXXXXXXXXXXXXXXXXX
X-Secure-RFC2821-MAIL-FROM: XXXXXXXXXXXXXXXXXXX
X-Secure-RFC2821-RCPT-TO:XXXXXXXXXXXXXXXXX
X-Secure-REMOTE-HOST: XXXXXXXXXXXXXXXXXXXX
X-Secure-REMOTE-ADDR: XXXXXXXXXXXXXXXXXXXXX
X-Secure-pp1t: X
X-Secure-trat: XX
X-Secure-omc: X
X-Secure-tsist: XXX
X-Secure-urt: XXX
X-Secure-art: X
X-Secure-drt: XXX
X-Secure-AS2-Class: XXXXXXXX
X-Secure-AS2-RefID: XXXXXXXXXXXXXXXXXXXXXXXXX
X-Spam-Status: Yes
X-Secure-Spam-Reason: XXXXXXXXXXXXXXXXXXXXXXXX


all i need it the ID at the top and the reason at the bottom. but heres the catch...........
This is a sample of !1! set in a txt file of thousands. so findstr or for /F??You can try this. Enter your file name after the search arguments:

Code: [Select]findstr /c:"X-Secure-Spam-Reason:" /c:"X-Secure-ID:" <replace with your file LABEL>

You can run this from the command line.

Good LUCK. Quote from: The_Valkyrie on July 06, 2010, 09:37:20 PM

What should I use to strip a text file?



C:\test>findstr "Secure-ID Secure-Spam-Reason" val.txt
X-Secure-ID:XXXXXXXXXXXXXXXXX
X-Secure-Spam-Reason: XXXXXXXXXXXXXXXXXXXXXXXX

C:\test>Quote from: marvinengland on July 07, 2010, 12:20:24 PM

C:\test>findstr "Secure-ID Secure-Spam-Reason" val.txt
X-Secure-ID:XXXXXXXXXXXXXXXXX
X-Secure-Spam-Reason: XXXXXXXXXXXXXXXXXXXXXXXX

C:\test>

that you sir. you are a master mind.
This just made my job a *censored* of a lot easier when i put it in a batch.
Quote from: The_Valkyrie on July 06, 2010, 09:37:20 PM
What should i use to strip a text file like:
you use a good text PROCESSING tool, or a language that does this job well for you.
For example, you can use gawk for Windows (or Perl/Python/Vbscript etc).

Code: [Select]C:\test>gawk -F":" "/X-Secure-ID|X-Secure-Spam-Reason/{print $2}" file
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX

Note, the one liner above gets you the actual ID and reason, excluding X-Secure-ID and X-Secure-Spam-Reason. If you
need the words "X-Secure-ID" and "X-Secure-Spam-Reason",

Code: [Select]C:\test>gawk -F":" "/X-Secure-ID|X-Secure-Spam-Reason/" file
X-Secure-ID:XXXXXXXXXXXXXXXXX
X-Secure-Spam-Reason: XXXXXXXXXXXXXXXXXXXXXXXX
ghostdog74, thanks for the brilliant reference to Gawk.

I was wondering if you or anyone could help with this issue, I'm trying to output the following numbers from this text file:


Analyzing pool.ntp.org (1 of 1)...
delayoffset from local clock
Stratum: 2

Warning:
Reverse name resolution is best effort. It may not be
correct since RefID field in time packets differs across
NTP implementations and may not be using IP addresses.



pool.ntp.org[155.101.3.115:123]:
ICMP: 73ms
NTP: +0.0162516s RefID: 127-67-113-92.pool.ukrtel.net [92.113.67.127]


What I want is in bold. How can I do this with Gawk? With my limited knowledge I can only output:
+0.0162516s RefID

But I would like to have just the numbers after +

Please and thanks in advance..


Discussion

No Comment Found