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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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  
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.