topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday November 16, 2025, 1:07 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: batch scripting  (Read 11118 times)

compn

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 57
    • View Profile
    • Donate to Member
batch scripting
« on: May 19, 2024, 09:34 PM »
i was doing a lot of grepping and it was causing a toll on my hands typing all the extra characters.

so i made a bat file

g.bat:
@echo off
grep -i %1 * | grep -i %2

now i'm wondering if i can make it so i just run it once, and i can just type the grep search words over and over again ?

what i mean is: instead of:
grep -i foo * | grep -i bar
grep -i foo1 * | grep -i bar1
and then, with bat file it looks like this:
g foo bar
g foo1 bar1

i can just do
g.bat
foo bar
(results for foo bar)
foo1 bar1
(results for foo1 bar1)
foo2 bar2
(results for foo2 bar2)

without having to type g each time.


also would be nice to be able to do g foo (it currently errors because the second grep is empty), or g foo bar zed hex whatever number of grep searches i need to do at once.

its been so long i cant remember what this stuff is even called in batch to search how to script it.

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,214
    • View Profile
    • Donate to Member
Re: batch scripting
« Reply #1 on: May 20, 2024, 05:26 PM »
i was doing a lot of grepping and it was causing a toll on my hands typing all the extra characters.
[...]
now i'm wondering if i can make it so i just run it once, and i can just type the grep search words over and over again ?
[...]
without having to type g each time.
[...]
its been so long i cant remember what this stuff is even called in batch to search how to script it.

There are still a few batch file resources on the web, e.g.


Don't overlook that even the Windows CMD prompt has line recall and editing.  When you've issued a command, and it's been executed, press Up Arrow to recall it, edit the line if necessary and press Enter to issue the modified command.  Take Command (payware) and its plain text console mode version TCC/LE (freeware) are far better. You get many more features than Microsoft ever dreamt of.  JP Soft seem to have replaced TCC/LE with TCC-RT : Free TCC Runtime for Batch Files, which I haven't tried.  Also, you should probably look at PowerShell, which also I haven't tried.

spencerbishop

  • Participant
  • Joined in 2025
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: batch scripting
« Reply #2 on: March 29, 2025, 11:53 AM »
I think what you're looking for is a way to loop through multiple grep searches without typing "g" each time. You can achieve that with a simple loop in your batch file.

compn

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 57
    • View Profile
    • Donate to Member
Re: batch scripting
« Reply #3 on: November 15, 2025, 04:31 PM »
yeah i couldnt figure out how to do what i wanted.

heres what my batch file looks like , i had ai help me write it.
@echo off
setlocal enabledelayedexpansion

if "%~3"=="" (
    if "%~2"=="" (
 grep -i %~1 *txt
    ) else (
 grep -i %~1 *txt | grep -i %~2
    )
) else (
 grep -i %~1 *txt | grep -i %~2 | grep -i %~3
)

endlocal

it works ok.
i have my file lists in .txt files:
so i can do
s search1
returns all results for search1
s search1 search2
returns all results for search1, then filtered for search 2
s search1 search2 search3
returns all results for search1, then filtered for search 2, then filtered for search3

but i still have to type s all the time :D
i just want it to be a prompt and i type search1 search2, hit enter, and it spits out results, asking me for the next search...