Grep from FTP Command

Posted on 2008-11-12
Last Modified: 2012-06-27
I automated a FTP session and was trying to grep from the ftp command. It worked for a few times and without the change in the script started returning Invalid Command for Grep on FTP. Did some search and figured Grep does not work on FTP. 2 Questions here:
1) Why did Grep work the first time around?
2) Is there a way I can incorporate Grep into FTP session?
>_temp.txt echo %1

>>_temp.txt echo %2

>>_temp.txt echo cd c:/logs

>>_temp.txt echo binary

>>_temp.txt echo prompt

>>_temp.txt echo get %YYMMDD%.log

>>_temp.txt echo cd e:/uname

>>_temp.txt echo put %YYMMDD%.log

>>_temp.txt echo grep <Text> %YYMMDD%.log ^> <Text>.log

>>_temp.txt echo get <Text>.log

>>_temp.txt echo bye

ftp -s:_temp.txt <Host>

Open in new window

Question by:megh345
    LVL 6

    Accepted Solution

    No, grep is not an ftp command.  However, if you want to run a shell based grep from within your ftp session, simply place a ! (escape to the shell) in front of it.  I.E.
    >>_temp.txt echo !grep <Text> %YYMMDD%.log ^> <Text>.log

    Author Comment

    Thanks Dathho, But I am running a batch from windows. so ! executes grep on cmd and returns a error that grep is not recognized as an internal or external command. Any further help will be greatly appreciated. Thanks in advance
    LVL 6

    Expert Comment

    In that case the find command should work for you.

    >>_temp.txt echo !find <Text> %YYMMDD%.log ^> <Text>.log  

    Author Comment

    Hmm Find truncates 1024 characters from every line. I have more characters than that in a line. Thanks for your quick response.
    LVL 6

    Expert Comment

    If you are Windows 2000 or newer you should be able to try the findstr command.  I don't know if it will have different behavior.
    LVL 40

    Expert Comment

    can you show the script with which grep was working?

    grep is not a ftp command and when run with ! it runs on the local system and not the remote one.


    Author Comment

    It was the same script where it worked.... It is when it stopped working that I noticed it was not a ftp command. I guess it was magical for a bit.. I couldn't figure out why either... :( .

    Dathho, I don't think FindStr will do any better than find command unfortunately..

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now