Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Dev Hardware ForumsSOFTWAREProgramming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Hardware Forums Sponsor:
  Trader Rating: 0 · #1  
Old June 9th, 2009, 02:00 PM
Reece Reece is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 Reece User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 56 sec
Reputation Power: 0
Using GREP with batch file? (prettying up a program)

Hey there everybody. I'm a beginner in batch, and I felt like trying an IP finding program. Really basic stuff, I know, but I'm still learning. I just installed GREP to use with my program, to basically clean up the look.

Code:
@echo off
TITLE IP Address Finder
echo Welcome to Reece's IP address finder!
echo.
echo.
ping -n 2 127.0.0.1>nul
echo How to use:
echo.
echo   1. Enter the desired URL.
echo   2. Press "Enter".
echo   3. You should see the message "Pinging (URL)".
echo   4. Look inside the brackets after the URL for the IP address of the website.
echo.
echo.
ping -n 2 127.0.0.1>nul
set/p "url=>"
ping -n 2 >nul
ping %url%
echo.
echo.
echo.
echo Press any key to exit.
pause>nul


I want to ping the site to find the IP address, and then use GREP to display what is inside the brackets to clean it up. Now, I currently have no idea how to do this... Could anybody help me out?


EDIT:

I figured it out. For those of you looking to do something similar, I'll go ahead and post the code below. =) (yes, I did use GREP)

Code:
@echo off
TITLE IP Address Finder
echo Welcome to Reece's IP address finder!
echo.
echo.
ping -n 2 127.0.0.1>nul
echo How to use:
echo.
echo   1. Enter the desired URL.
echo   2. Press "Enter". 
echo.
echo.
set/p "url=> "
echo.
echo.
ping %url% | grep -o -m 1 \[.*\]
echo.
echo.
echo Press any key to exit.
pause>nul


The
Code:
| grep -o -m 1 \[.*\]
was all I was missing. It cleaned it up very nicely. Feel free to use this code if you need it.

Last edited by Reece : June 9th, 2009 at 03:59 PM. Reason: Figured it out

Reply With Quote
  Trader Rating: 0 · #2  
Old July 14th, 2009, 09:21 PM
omrsafetyo's Avatar
omrsafetyo omrsafetyo is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Maine, USA
Posts: 305 omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level)omrsafetyo User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Days 22 h 55 m 17 sec
Reputation Power: 223
Send a message via AIM to omrsafetyo
Yeah - I would certainly suggest to anyone that wants to write scripts in windows to install the Unix Utils as a windows component. This will certainly make batch scripting much more efficient.

Reply With Quote
  Trader Rating: 0 · #3  
Old July 14th, 2009, 10:20 PM
JohnFrank's Avatar
JohnFrank JohnFrank is offline
Contributing User
Click here for more information
Click here for more information
 
Join Date: Jan 2008
Location: Lilyfield NSW Australia
Posts: 1,561 JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)JohnFrank User rank is General 116th Grade (Above 100000 Reputation Level)  Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44Folding Points: 21974789 Folding Title: Super Ultimate Folder - Level 44
Time spent in forums: 2 Weeks 6 Days 22 h 52 m 47 sec
Reputation Power: 8694
Send a message via MSN to JohnFrank
If the purpose is to learn and develop your knowledge on scripts then well done you off to a good start.

You should try and add some more features like an option to look up another (second and subsequent) URL and an option to read it the URL from the command line parameters that executed the script (and bypass the first time input prompt).
__________________

Reply With Quote
Reply

Viewing: Dev Hardware ForumsSOFTWAREProgramming > Using GREP with batch file? (prettying up a program)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
     
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek