The code I need to implement in a Windows batch file is like this (it is currently in Perl):
while(<file>)
{
if($_ =~ m/xxxx/)
{
print OUT "xxxx is found";
}
elsif($_ =~ m/yyyy/)
{
next;
}
else
{
($a,$b) = split(/:/,$_);
$array1[$count] = $a;
$array2[$count] = $b;
$count++;
}
}
My questions are:
- Is this level of complexity possible in Windows batch files?
- If so, how can I put an If condition
inside a for loop to read a text
file?
Thanks for your attention. If you know the answers, or have any ideas/clues on how to reach the answer, please share them.
EDIT: I am working in Windows. I can use only whatever is provided with Windows by default and that means I cant use Unix utilities.
Best Solution
Putting
if
intofor
in general is easy:A
for
loop that iterates over lines can be written using/f
switch:Regexps are provided by
findstr
. It will match againststdin
if no input file is provided. You can redirect output toNUL
so that it doesn't display the found string, and just use itserrorlevel
to see if it matched or not (0 means match, non-0 means it didn't). And you can split a string using/f
again. So: