Is there a Pattern Matching Utility like GREP in Windows? - windows

Is there a similar utility to grep available from the Windows Command Prompt, or is there a third party tool for it?

There is a command-line tool called FINDSTR that comes with all Windows NT-class operating systems (type FINDSTR /? into a Command Prompt window for more information) It doesn't support everything grep does but it might be sufficient for your needs.

PowerShell (included as standard on Windows 7/2008R2, optional for XP/2003/Vista/2008) which includes the select-string cmdlet for this purpose.

Grep for Windows by GnuWin Project (2014-10-02: It's outdated, see comments below)

as mentioned, findstr works fine. example :
C:>dir | findstr Windows
11/06/2013 09:55 PM Windows

I'm surprised no one has mentioned FINDSTR. I'm no grep poweruser, but findstr does what I need it to, filter files and stdin, with some primitive regex support. Ships with Windows and all that. (Edit: Well someone did mention findstr, It's late I guess)

Cygwin grep and more ;)

I also found one more way of utilizing GREP like functionality in Windows 7 and above without any extra application to install and on older systems you can use install Powershell.
In Powershell, User can use Where-Object it has quite comprehensive set of feature that provides all the functionality of GREP plus more.
Hope It helps.

GnuWin32 is worth mentioning, it provides native Win32 version of all standard linux tools, including grep, file, sed, groff, indent, etc.
And it's constantly updated when new versions of these tools are released.

On Windows I use Far Manager for file search. BSD licensed, works in console, saves time on typing cmdline parameters. Here is its search dialog invoked by Alt-F7.

UnxUtils is a great set of Unix utilites that run on Windows. It has grep, sed, gawk, etc.

An excellent and very fast file search utility, Agent Ransack, supports regular expression searching. It's primarily a GUI utility, but a command-line interface is also available.

Update: This wasn't true when the question was originally asked, but now Microsoft lets one Install the Windows Subsystem for Linux, and Windows will then run grep. In PowerShell, run:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

In the windows reskit there is a utility called "qgrep". You may have it on your box already. ;-) It also comes with the "tail" command, thank god!

You have obviously gotten a lot of different recommendations.
My personal choice for a Free, 3rd Party Utility is: Agent Ransack
Agent Ransack Download
Despite its somewhat confusing name, it works well and can be used in a variety of ways to find files.
Good Luck

the all-in-one busybox contains grep / egrep / sed / awk and MANY more
get it from:
http://frippery.org/busybox/index.html
http://frippery.org/files/busybox/?C=M;O=D
Update: no longer available - or some older
https://github.com/pclouds/busybox-w32

Although not technically grep nor command line, both Microsoft Visual Studio and Notepad++ have a very good Find in Files feature with full regular expression support. I find myself using them frequently even though I also have the CygWin version of grep available on the command line.

I'll add my $0.02 to this thread. dnGREP is a great open source grep tool for windows that supports undo, windows explorer integration, search inside PDFs, zips, DOCs and bunch of other stuff...

Yes there is only one program for Windows PC which have solid GUI and it is essential util for me. I work as a developer and on every computer I've had, first thing install XFind program. It is created in 1997 and till now version is 1.0 and till now works and it is the best. Frequently I need to search some string in a ".cs", ".aspx", ".sct" (Visual FoxPro form code file) or just ".*" and XFind scans all files and show me files and another great thing is that you can look where string is in the file. XFind has also some kind of editor. If it binary file it will show you string finded. Try it and use it forever if you are developer like me.

I realize its an old question but I came across this post seeking an answer. And I have found one so adding it here for the collective internet memory
Powershell: Select-String
Module:
Microsoft.PowerShell.Utility
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string
and an informative blog post with advanced examnples: "How to “grep” in PowerShell"
https://antjanus.com/blog/web-development-tutorials/how-to-grep-in-powershell/
A simple example from that blog post:
cat package.json | Select-String -Pattern webpack
ls ./src/components/ | Select-String -Pattern View
C:> cat post.md | Select-String -Pattern "^\w*:"

Bare Grep is nice if you want a GUI. Gnu grep is good for CLI

If you don't mind a paid-for product, PowerGREP is my personal favorite.

We have recently used PowerGREP for some fairly advanced bulk operations on thousands of files. Including regex searching in content of PDF files, and altering PDF documents in largescale.
Its worth the money if you want to save time from manuel labour. You can try it before you buy i think.

If you have to use bare Windows, then in addition to the Powershell option noted above, you can use VBScript, which has decent RegEx support.
MS also has a decent scripting area on Technet with a ton of examples for administrators.

Just try LikeGrep java utility.
It may help you in very many cases.
As you wish, it can also replace some text, found in files.
It garantees its work on large files (up-to 8 Gb tested)

As mentioned above, the gnuwin32 project has a Windows CLI version of grep.
If you want something with a graphical interface, I would recommend the (open-source) tool AstroGrep.

It has been a while since I've used them, but Borland (Embarcadero now) included a command line grep with their C/C++ compiler. For some time, they have made available their 5.5 version as a free download after registering.

There's a commercial grep utility available from Oak Road Systems.

I recommend PowerGrep
I had to do an e-discovery project several years ago. I found that fisdstr had some limitations, most especially fisdstr would eventually fail
the script had to search across thousands of files using a couple of dozen search terms/phrases.
Cygwin's grep worked much better, it didn't choke often, but ultimately I went to PowerGrep because the graphical interface made it much easier to tell when and where it crashed, and also it was really easy to edit in all the conditionals and output that I wanted. Ultimately PowerGrep was the most reliable of the three.

I know that it's a bit old topic but, here is another thing you can do. I work on a developer VM with no internet access and quite limited free disk space, so I made use of the java installed on it.
Compile small java program that prints regex matches to the console. Put the jar somewhere on your system, create a batch to execute it and add the folder to your PATH variable:
JGrep.java:
package com.jgrep;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JGrep {
public static void main(String[] args) throws FileNotFoundException, IOException {
int printGroup = -1;
if (args.length < 2) {
System.out.println("Invalid arguments. Usage:");
System.out.println("jgrep [...-MODIFIERS] [PATTERN] [FILENAME]");
System.out.println("Available modifiers:");
System.out.println(" -printGroup - will print the given group only instead of the whole match. Eg: -printGroup=1");
System.out.println("Current arguments:");
for (int i = 0; i < args.length; i++) {
System.out.println("args[" + i + "]=" + args[i]);
}
return;
}
Pattern pattern = null;
String filename = args[args.length - 1];
String patternArg = args[args.length - 2];
pattern = Pattern.compile(patternArg);
int argCount = 2;
while (args.length - argCount - 1 >= 0) {
String arg = args[args.length - argCount - 1];
argCount++;
if (arg.startsWith("-printGroup=")) {
printGroup = Integer.parseInt(arg.substring("-printGroup=".length()));
}
}
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
}
Matcher matcher = pattern.matcher(sb.toString());
int matchesCount = 0;
while (matcher.find()) {
if (printGroup > 0) {
System.out.println(matcher.group(printGroup));
} else {
System.out.println(matcher.group());
}
matchesCount++;
}
System.out.println("----------------------------------------");
System.out.println("File: " + filename);
System.out.println("Pattern: " + pattern.pattern());
System.out.println("PrintGroup: " + printGroup);
System.out.println("Matches: " + matchesCount);
}
}
c:\jgrep\jgrep.bat (together with jgrep.jar):
#echo off
java -cp c:\jgrep\jgrep.jar com.jgrep.JGrep %*
and add c:\jgrep in the end of the PATH environment variable.
Now simply call jgrep "expression" file.txt from anywhere.
I needed to print some specific groups from my expression so I added a modifier and call it like jgrep -printGroup=1 "expression" file.txt.

Use Cygwin...
it has 32 and 64 bits versions
and it works fine from Windows 2000 (*)
to Windows 10 or Server 2019
I use Cygwin for a long time...
and recently tryed to substitute with Windows-Linux-Subsystems...
not for long...
I quickly went back to Cygwin again...
much more flexible, controlable and rich...
also less intrusive...
just add \bin to the path...
and you can use it anyware in Windows/Batch/Powershell...
or in a DOS-Box... or in a Powershell-Box...
Also you can install a ton of great packages
that really work... like nginX or PHP...
I even use the Cygwin PHP package in my IIS...
As a bonus wou can also use it from a bash shell...
(I think this was the original intent ;-))

Related

How do we work with OS-independent paths in Perl 6?

Perl 6 does have classes that include common OSs for specifying paths, as well as $*SPEC which contains the file specification. New paths use by default current value of SPEC. However, it's not clear at all, from the documentation, if doing something like
mkdir IO::Path.new( 'a/b/c' );
is going to work correctly across all operating systems, or you need to specifically create OS-dependent code. Any idea?
I'm trying this on Windows 7 (one of the OSes you seem to be mostly interested in according to tags), using
This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03
implementing Perl 6.d.
And it seems to work just like that
> with mkdir IO::Path.new('a/b/c') { say .e; say .absolute }
True
C:\rakudo\a\b\c
The directory is indeed created properly.
Note that IO::Path takes an IO::Spec object defaulting to $*SPEC in its constructor, so the necessary OS-dependent part is available to the object. In Rakudo the IO::Spec is indeed used by mkdir through .absolute.
There also is a roast test about / in an IO::Path becoming \ on Windows.
As Elizabeth Mattijsen pointed out, Windows seems to just support forward slashes by itself. Others claim that this has been the case forever:
Actually, every version of Windows, and every version of MS-DOS from 2.0 on, has accepted "/" as a path delimiter.
On a Windows 10 Enterprise VM:
C:\Users\me>c:/rakudo/bin/perl6 -e "mkdir IO::Path.new( 'a/b/c' )"
C:\Users\me>tree a
Folder PATH listing
Volume serial number is xxx
C:\USERS\ME\A
└───b
└───c

How to remove a reoccuring word/character and what comes after, from the filenames of multiple files?

I have several folders of video files where, due to the download manager I use, they are all named in the following format "FILENAME.mp4; filename= FILENAME.mp4" All I've been trying to do is to remove everything after (and including) ".mp4; filename". However, I haven't found a way to do this.
I have tried some free software (such as Renamer, Namechanger, Name Munger for Mac, Transnomino) but I failed to do what I need to.
I'm working on Mac OSX 10.13.6.
Any help with this issue would be appreciated.
You can achieve it using Terminal. Go to the folder where you want to rename files using this cd command, for example:
cd ~/Documents/Videos
And run this command to rename all files recursively:
find . -iname "*.mp4;*" | sed -E 's/(\.[^\.]*)(\.mp4)(.*)/mv "\1\2\3" "\1\2"/' | sh
This command will keep only FILENAME.mp4 part from FILENAME.mp4; filename= FILENAME.mp4 file name
I used to extensively use a windows Rename tool called Renamer 6.0, and it had a "pattern rename" facility called "Multi change" that could have handled this.
In the context of that tool it would be asking for a source pattern like %a= %b and a destination pattern (like %b), everything after the = would be stored in %b variable and then renaming the file to just %b would lose everything after the =
See if your preferred rename tool has a similar facility?
If your tool supports regex, then find: .*?=(.*) and replace with $1
I'm also minded that asking this question on https://unix.stackexchange.com/ might elicit some help crafting a shell script that will perform this rename (though also plenty of shell capable people here, one of them may see it - it's just that it's not quite as hardcore programmer-y a question as most).
If you're willing to learn/use java, then that could be another good way to get the problem solved. It would (at a guess) look something like this:
for (final File f : new File("C:\\temp").listFiles()) {
if (f.isFile()) {
string n = f.getName();
if (n.contains("=")) {
f.renameTo(new File(n.substring(n.indexOf("=")+1));
}
}
}

Does jq have a filepath length limit?

(OS is Windows 7 Professional. jq is version 1.5.)
I've been using jq to automate prettifying some JSON files (with Python). It seems to me after some time trying to determine why it wasn't working that jq fails silently when working with a file path string that's length 28, or simply stops working if the file path string is length 29 or more.
E.g. on cmd (and it's worth pointing out that I made a kind of shortcut so that jq calls jq-win64.exe, and tested the latter directly as well, so that's not the source of the issue):
C:\jq>jq . 123456789012345678901234567
displays prettified content of the file;
C:\jq>jq . 1234567890123456789012345678
displays nothing; and
C:\jq>jq . 12345678901234567890123456789
causes a "jq-win64.exe has stopped working" window.
(I also tested this on JSON files within folders; the common point was that the input string be of length 28 or more including slashes to fail.)
Is this a bug? If it's not, what can I do to work around it Okay, I admit that was a stupid question, I can work around it by copying content into a temp file in the base folder, prettify it, and then save it back to wherever I want it to be. More on-point question: is this the best workaround available for me to take?
There was a Windows-specific bug in jq 1.5 (see e.g. https://github.com/stedolan/jq/issues/1094). It was fixed shortly after the release of jq 1.5.
To obtain a post-1.5 .exe for Windows, see any of:
https://chocolatey.org/packages?q=jq
https://stedolan.github.io/jq/download
https://github.com/stedolan/jq/wiki/Installation#windows-using-appveyor

Processing 3.0 launch() function doesn't launch my .exe

Processing 3.0 launch function doesn't launch my .exe.
I am using the Launch() function (https://processing.org/reference/launch_.html)
launch("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
Or
launch("C:/app/keyboard.exe");
Result: Chrome browser will open. keyboard.exe will not. I've tryed different locations and relative paths.
I only get a windows loader when the link is correct. So that is correct.
The function discriptions says this:
"Be sure to make the file executable before attempting to open it (chmod +x). "
https://superuser.com/questions/106181/equivalent-of-chmod-to-change-file-permissions-in-windows
I also made a .bat file to execute the .exe but the launch() function only works on exe files.
but that didnt work either.
System:
Processing 3.0
Java 8
Windows 10, 64 bit
So what am I missing?
It is a bit dodgy but works in windows 8:
PrintWriter output=null;
output = createWriter("myfile.bat");
output.println("cd "+sketchPath(""));
output.println("start archivo.exe");
output.flush();
output.close();
output=null;
launch(sketchPath("")+"myfile.bat");
And you can choose another relative or absolute path
for instance
output.println("cd ..");
output.println("cd directoriy");
...
As Samuil advises, Windows uses \ instead of a / as a separator character, which you'll need to escape, hence \\: launch("C:\\app\\keyboard.exe");
I recommend using File.separator:
launch("C:"+File.separator+"app"+File.separator+"keyboard.exe");
It's a bit longer, but will work regardless of the operating system(Linux/OSX/Windows/etc.).
Aside launch(), also try exec():
exec(new String[]{"start","C:"+File.separator+"app"+File.separator+"keyboard.exe");
also Process. (If you need to check the output, you may need to write your own thread that will pipe the output)

Command line SVN help to check the working copy is an outdated copy of the one present in the server

Hello
I want to implement the following flow in my application.(as shown in the pseudocode)
LatestRevision = IsMyFileLatest(); // some method which should check the svn and compare the working copy of the file.
if (! LatestRevision) //this flag compares with the Head Revision
{
//Display error message..The file is not the latest copy
}
else
{
// Commit the file changes in the subversion server
FileCommit(); //commits the file(whichever file im working to the server)
}
For this i need help of the following svn commands executed in the command line.
to check whether the current file is the latest file ?
committing only those files which are modified..in a directory.
Any help or pointers regarding the subversion command line is deeply appreciated.
Thanks and Best regards
The VisualSVN site hosts a 'book' on Subversion, located here, which should give you a good starting point - though off the top of my head I'm not sure of the exact commands you'd need to use...
There is a chapter which is a reference for commands:
SVN Reference.
Explained there is svn info which may help you out well enough.
EDIT:
On the other hand, after reading your altered title, svn status may be what you're looking for?
EDIT 2:
Ok, given that the programming language used in your question is not explicitly stated, and the fact it's such a common syntax that we could liken the guesswork to that of beating a dead horse, here's a little snippet in the universal (in the Windows world) VBScript...
Dim shell, svn
Set shell = CreateObject("WScript.Shell")
Set svn = shell.Exec("svn info [working_copy_path]")
WScript.Sleep 1000
Dim revision
Do While svn.StdOut.AtEndOfStream <> True
revision = svn.StdOut.ReadLine
If left(revision, 8) = "Revision" Then
Exit Do
End If
Loop
WScript.Echo revision
I'm far from proud of the Sleep mechanism utilised, but luckily I'm not the one with (much of) a responsibility here, so I'll leave generating a clean-cut approach to yourself and just put this out there as an example.

Resources