Solved

using findstr to output

Posted on 2010-11-13
4
1,946 Views
Last Modified: 2012-05-10
The other day I used a command that worked fine, but its output required me to do some hands-on work in Excel to get exactly the output I wanted to copy/paste into an email.

Here was the command (sample IP)...

ping -a 10.10.10.10 | findstr /i "Pinging" >> .\hostnames.txt

I am looking for a way to grep or findstr only the hostname. Do you know if I can do this simply using the old CMD tools?

Thanks!
JohnD
0
Comment
Question by:johndarby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
fhmc earned 500 total points
ID: 34129538
could try the following via batch or command line:

ping -a 10.10.10.10| find /i "pinging" > %temp%\pingtest.txt
for /f "tokens=2" %a in (%temp%\pingtest.txt) do echo %a >> .\hostnames.txt


or

you could try:

ping -a 10.10.10.10| for /f "tokens=1,2" %a in ('find /i "Pinging"') do echo %b >> .\hostnames.txt

note1 -  a double quotation mark followed by a single quotation mark follows the word Pinging.
note2 - if you plan to execute either suggestion above via a batch file you will need to add an extra % in front of the 'for' variables.

ex.  for /f "tokens=2" %%a...  etc.
0
 
LVL 7

Assisted Solution

by:fhmc
fhmc earned 500 total points
ID: 34133550
you could also directly pipe the command line output to the clipboard:

ping -a 10.10.10.10| for /f "tokens=1,2" %a in ('find "Pinging"') do echo %b| "clip"

you could then create a new e-mail message and CTRL-V or SHIFT-INS the hostname directly into the body.
0
 
LVL 1

Author Comment

by:johndarby
ID: 34133598
The clipboard...never knew how to do that. Thanks bro!
0
 
LVL 1

Author Closing Comment

by:johndarby
ID: 34139786
You rock, my friend...thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
printf performancy 11 100
Where to download python requests library 6 105
Hide file extensions in Notepad++ tabs 2 80
Automate and generate Azure reports for the following items 3 73
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question