Grep from FTP Command

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

Who is Participating?
dathhoConnect With a Mentor Commented:
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
megh345Author Commented:
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
In that case the find command should work for you.

>>_temp.txt echo !find <Text> %YYMMDD%.log ^> <Text>.log  
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

megh345Author Commented:
Hmm Find truncates 1024 characters from every line. I have more characters than that in a line. Thanks for your quick response.
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.
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.

megh345Author Commented:
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..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.