grep

Groovy grep a word

I wanted to grep for java process and then find the max heap memory used. I tried this def ex =['sh','-c','ps -aef | grep Xmx']; String str = ex.execute().text; while str has something like " java -Xmx1024M /kv/classes/bebo/ -Xms512M" How do I extract the value 1024M. I was planning to user java regex but thought someone might know a ...

How can I extract lines of text from a file?

I have a directory full of files and I need to pull the headers and footers off of them. They are all variable length so using head or tail isn't going to work. Each file does have a line I can search for, but I don't want to include the line in the results. It's usually *** Start (more text here) And ends with *** Finish (more te...

Useful Regular Expression Tutorial

Hi I'm looking for a good tutorial on using regular expressions especially with grep. I tried googling for some but most tutorials are too basic and cover things I already know. ...

Efficient grep method to match two atoms?

I'm looking for a method to grep for multiple atoms e.g. "foo" and "bar". I'm aware i can use grep 'foo' file | grep 'bar' to get both of them but i was wondering if there was a more efficient way. Any googleing seems to only throw results for an 'or' based search rather than 'and'. ...

What is makeinfo, and how do I get it?

I'm trying to build GNU grep, and when I run make, I get: [snip] /bin/bash: line 9: makeinfo: command not found What is makeinfo, and how do I get it? (This is Ubuntu, if it makes a difference) ...

How to include ' ' and ',' in regular expression \w?

How can I include a blank space ' ' and a comma ',' in this simple regular expression? \w{1,64} \w corresponds to: [A-Za-z0-9_], viz avery char between a-z (case sensitive/insensitive), numbers between 0-9 and the underscore. I need to add space and comma to this. I've been trying directly whit [A-Za-z0-9_, ] but this did allow cha...

How can I extract all quotations in a text?

I'm looking for a SimpleGrepSedPerlOrPythonOneLiner that outputs all quotations in a text. Example 1: echo “HAL,” noted Frank, “said that everything was going extremely well.” | SimpleGrepSedPerlOrPythonOneLiner stdout: "HAL," "said that everything was going extremely well.” Example 2: cat MicrosoftWindowsXPEula.txt | SimpleG...

How do I use a variable in a grep with groovy?

I need to grep for lines with bunch of names, say "[email protected]", "[email protected]" from a file.txt file.txt has junk which is [email protected] [email protected]. I need to filter these out Once I get these lines I need to grep for gmail and yahoo and get their counts List l = new ArrayList{[email protected], [email protected]}...

What is the best way to find and replace "!= null" code with andand?

I refactor my code and I am looking for a solution to grep my source files for something like if ( user && user.name && user.name.length() < 128 ) ... in order to replace it later with ruby's andand or groovy's ?. operator (safe navigation operator). ...

Using grep with regular expression to filter out matches

I'm trying to use grep with -v for invert-match along with -e for regular expression. I'm having trouble getting the syntax right. I'm trying something like tail -f logFile | grep -ve "string one|string two" If I do it this way it doesn't filter If I change it to tail -f logFile | grep -ev "string one|string two" I get grep: s...

How can I quickly find the first line of a file that matches a regex?

I want to search for a line in a file, using regex, inside a Perl script. Assuming it is in a system with grep installed, is it better to: call the external grep through an open() command open() the file directly and use a while loop and an if ($line =~ m/regex/)? ...

Search Javascript Array for Regex and return True/False (0/1) if found

I need to know how I can search an array for some literal text and have it used as a condition whether to continue. Heres why: Each time I execute a function I am pushing the ID of the property it acts upon into an array. I need my funtion to check if that ID is in the array already and if it is, remove it and execute my other function ...

count all occurrences of string in lots of files with grep

I have a bunch of log files. I need to find out how many times a string occurs in all files. grep -c string * retruns ... file1:1 file2:0 file3:0 ... Using pipe I was able to get only files that have one or more occurrence: grep -c string * | grep -v :0 ... file4:5 file5:1 file6:2 ... How to get only the combined count? (If it ...

Linux using grep to print the file name and first n characters

How do I use grep to perform a search which, when a match is found, will print the file name as well as the first n characters in that file? Note that n is a parameter that can be specified and it is irrelevant whether the first n characters actually contains the matching string. ...

findstr or grep that autodetects chararacter encoding (UTF-16)

I want to do this: findstr /s /c:some-symbol * or the grep equivalent grep -R some-symbol * but I need the utility to autodetect files encoded in UTF-16 (and friends) and search them appropriately. My files even have the byte-ordering mark FFEE in them so I'm not even looking for heroic autodetection. Any suggestions? Thanks,...

How do I find the case-insensitive unique elements of two arrays in Perl?

I have three arrays. @array1 containing filenames @array2 containing filenames @unique which I want to contain the unique items I use the following code to compare the two arrays and output a third array that contains the unique filenames. @test{@array1} = (); @unqiue = grep {!exists $test{$_}} @array2; However the output is case...

How can I scan multiple log files to find which ones have a particular IP address in them?

Recently there have been a few attackers trying malicious things on my server so I've decided to somewhat "track" them even though I know they won't get very far. Now, I have an entire directory containing the server logs and I need a way to search through every file in the directory, and return a filename if a string is found. So I tho...

Linux pipe output to grep

I want to pipe the output of grep as the search patter for another grep. As an example: grep <Search_term> <file1> | xargs grep <file2> I want the output of the first grep as the search term for the second grep. The above command is treating the output of the first grep as the file name for the second grep. I tried using -e option fo...

how do I grep through a mysql database?

Looking for a nifty helper function/method for grepping through all defined tables, columns, stored procedures, etc, for a MySql database. I had something similar for SQL Server. ...

Distinct quickfix buffers for vimgrep and make

When 'make'-ing under vim, there is often a need to vimgrep the files. In such cases, vimgrep takes over the quickfix buffer, so one needs to re-make in order to browse remaining compiler errors. Is there a way to avoid this mess? ...