grep

Python modules for visualization of C++ code

I'm looking for python modules that can help with grepping C++ code. I have a large code base that I would like to do some analysis on. Ultimately I would like to come up with a graphical map of the software. There is lots of message passing going on amongst apps so I would like to be able to capture that information and present it vi...

Get total number of matches for a regex via standard unix command

Let's say that I want to count the number of "o" characters in the text oooasdfa oasoasgo My first thought was to do grep -c o, but this returns 2, because grep returns the number of matching lines, not the total number of matches. Is there a flag I can use with grep to change this? Or perhaps I should be using awk, or some other comm...

In Bash, how to write alias or function for "export GREP_COLOR='1;32'; grep --color" ?

grep doesn't allow setting color by grep --color='1;32' (1 meaning bold, and 32 meaning green). It has to use GREP_COLOR by export GREP_COLOR='1;32' and then use grep --color How do we alias or write a function for grep so that we have 2 versions of grep (say, grep and grepstrong), one for usual green font, and the other one, gr...

Using grep/find combination to find the usages of a function or a struct

I am wondering how I can effectively find the usages of a function/structure in the files using find & grep combination. For example, I have source code for git on my machine. If you look at the commit.h, you can see commit structure is defined like, struct commit { struct object object; void *util; unsigned int indegree; ...

Linux Grep - how to display only string that matched the regular expression

I am basically grepping with a regular expression on. Now in the output i would like to see only the strings that match my reg exp. In a bunch of xml files (mostly they are single line files with huge amomunt of data in a line), i would like to get all the words that start with MAIL_ Also the grep command on the shell should give only...

how to remove blank lines with grep

I tried grep -v '^$' in Linux and that didn't work. This file came from a Windows file system. ...

How to print a line with a pattern which is nearest to another line with a specific pattern?

I want to find a pattern which is nearest to a specific pattern. Such as I want to print "bbb=" which is under the "yyyy:" (it is the closest line with bbb= to yyyy). It is line 8. line numbers and the order might be changed so it is better not to use line numbers. root# vi a "a" 15 lines 1 ## xxxx: 2 aaa=3 3 bbb=4 4 ccc=2 ...

How to find commit SHA1 of a tree containing a file containing a given string

This is the situation: I've lost some work in my git repository, this work was once commited, but is now burried in my history, somewhere that might be unreachable by 'git log --all'. The only thing I've can remember is some distinct string that could pinpoint a file that is part of my work at this time. I've got a solution... but it is...

Perl system command not acting as a normal prompt

I am trying to modify a perl script to comment out all lines matching some pattern. In normal command prompt, here is the line I'm trying to add: grep -lIRZ --exclude="*\.svn*" "pattern" . | xargs -0 -l sed -i -e 's/.*pattern.*/\/\/&/g' Here it is in the context of the perl script: my $rmcmd = "grep -lIRZ --exclude=\"*\\.svn*\" \"pa...

RegEx for finding words with NOT ONLY ONE space between them.

Hello. I need help with a RegEx problem: I want to find occurences of two known words ("foo" and "bar" for example), that have any white space other than EXACTLY ONE SPACE CHARACTER between them. In the text that I have to grep, there may be spaces, tabs, CRs, LFs or any combination of them between the two words. In RegEx words: I ne...

Regular expression issue

Hello, may be this is newbie question, but I must ask it! In general I'm understand regular expressions, but I don't understand, why this one: ^.{8}[[:blank:]]{2} works on this line: prelink: /lib/libkeyutils-1.2.so: at least one of file's dependencies has changed since prelinking in this grep command: echo "prelink: /lib/libkeyut...

extract digits between 2 patterns awk/egrep

I want to extract the variable # of digits between two patterns, eg: correction: blah blah.... AAM #6,blah blah blah blah.... AAM #10 , blah blah blah blah.... AAM #100 , blah blah output: 6, 10 and 100 I need to extract numbers between "AMA #" and comma ...

Alternating chars and nested parenthesesin (e)grep

I'm looking for a regex that finds all words in a list that do not have characters next to each other that are the same. (this is an exercise) So abcdef is printed, but aabcdef is not. I tried both egrep "^((.)[^\1])*$" and egrep "^((.)[^\2])*$" words but, other than being not sure which one would be right, they don't work. I k...

Extracting n rows of text from a large csv file

I have a CSV file (foo.csv) with 200,000 rows. I need to break it into four files (foo1.csv, foo2.csv... etc.) with 50,000 rows each. I already tried simple ctrl-v/-c using gui text editors, but the my computer slows to a halt. What unix command(s) could I use to accomplish this task? ...

Regex: Match only if string A is found and string B is not

I'm trying to write a regular expression that will essentially return true if string A is found and string B is not found. To be more specific, I'm looking for any file on my server which has the text 'base64_decode' in it, but not 'copyright'. Thanks! ...

Bash: escape characters in backticks

I'm trying to escape characters within backticks in my bash command, mainly to handle spaces in filenames which cause my command to fail. The command I have so far is: grep -Li badword `grep -lr goodword *` This command should result in a list of files that do not contain the word "badword" but do contain "goodword". ...

Grepping only certain lines of files

I have a collection of files in a directory which I would like to search for a particular regular expression (=([14-9]|[23][0-9]), as it happens). But I only care when this pattern falls on the second, sixth, tenth, ..., 4n+2-th line. Is there a good way to do this? ...

sed output stagnate

I have file names that map to directores. For example. test ---> /to/path/test/program.c I have a line that formats the output of sed into this currently test0 test1 test3 All unique directories, I now need to add leading path and copy their respective c files. Is there a way to stagnate the output of sed while i carry about ther...

Extracting text in between strings

How do I extract text in between strings with very specific pattern from a file full of these lines? Ex: input:a_log.gz:make=BMW&year=2000&owner=Peter I want to essentially capture the part make=BMW&year=2000. I know for a fact that the line can start out as "input:(any number of characters).gz:" and end with "owner=Peter" ...

Extract string from string using RegEx in the Terminal

I have a string like first url, second url, third url and would like to extract only the url after the word second in the OS X Terminal (only the first occurrence). How can I do it? In my favorite editor I used the regex /second (url)/ and used $1 to extract it, I just don't know how to do it in the Terminal. Keep in mind that url is a...