grep

How to extract a substring matching a pattern from a Unix shell variable

I'm relatively new to Unix shell scripting. Here's my problem. I've used this script... isql -S$server -D$database -U$userID -P$password << EOF > $test exec MY_STORED_PROC go EOF echo $test To generate this result... Msg 257, Level 16, State 1: Server 'MY_SERVER', Procedure 'MY_STORED_PROC': Implicit conversion from datatype 'VARCHA...

How do I write a bash alias/function to grep all files in all subdirectories for a string?

I've been using the following command to grep for a string in all the python source files in and below my current directory: find . -name '*.py' -exec grep -nHr <string> {} \; I'd like to simplify things so that I can just type something like findpy <string> And get the exact same result. Aliases don't seem sufficient since they on...

How to run a dictionary search against a large text file?

We're in the final stages of shipping our console game. On the Wii we're having the most problems with memory of course, so we're busy hunting down sloppy coding, packing bits, and so on. I've done a dump of memory and used strings.exe (from sysinternals) to analyze it, but it's coming up with a lot of gunk like this: ''''$$$$ %%%% ...

Setting grep end of line character

I have a fairly simple bash script that does some grep to find all the text in a file that does not match a pattern. grep -v $1 original.txt >trimmed.txt The input file ends each line with the Windows line end characters, i.e., with a carriage return and a line feed CR LF. The output of this command (run in Cygwin) ends each line wit...

Trying to grep cygwin output from cvs commands

Hi All, I am trying to find an easy way to see what files I have modified in my checked out code by running either cvs update or cvs status and limiting the output to the files I have modified. I started by doing variations on: cvs update | grep "M " // this did nothing useful. cvs update | grep -e "M " * // this got me all the files...

How can I find all empty try ... except blocks with GExperts grep?

In new versions of GExperts, the grep utility now supports more 'expert' expressions. I have not yet found a way to locate empty try ... except blocks in Delphi sources using regular expressions, how could I do this with the GExperts grep tool? ...

How do you pipe input through grep to another utility?

I am using 'tail -f' to follow a log file as it's updated: tail -f logfile I next pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case): tail -f logfile | grep org.springframework The third step I'd like to make is piping the output from grep to a third command, '...

Can you grep a file using a regular expression and only output the matching part of a line?

I have a log file which contains a number of error lines, such as: Failed to add [email protected] to database I can filter these lines with a single grep call: grep -E 'Failed to add (.*) to database' This works fine, but what I'd really like to do is have grep (or another Unix command I pass the output into) only output the email ad...

Colorized grep -- viewing the entire file with highlighting

I find grep's --color=always flag to be tremendously useful. However, grep only prints lines with matches (unless you ask for context lines). Given that each line it prints has a match, the highlighting doesn't add as much capability as it could. I'd really like to cat a file and see the entire file with the pattern matches highlighted....

Filter filenames by pattern

I need to search for files in a directory that begin with a particular pattern, say "abc". I also need to eliminate all the files in the result that end with ".xh". I am not sure how to go about doing it in Perl. I have something like this: opendir(MYDIR, $newpath); my @files = grep(/abc\*.*/,readdir(MYDIR)); # DOES NOT WORK I also ...

find & replace part of text

I am trying to do a search and replace using GREP/Regex Here is what I am searching for <div align="center" class="orange-arial-11"><b>.+<br> I want to remove the <b>, <br> tags, and place <h3> tags around what .+ finds. But I can't get what .+ finds to stay when it does the replace. For example, I want to find this <div align="ce...

Unable to grep a specifiallyFormatted text

I run man gcc | grep "-L" I get Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. How can you grep the match? ...

Unix command to find string set intersections or outliers?

Is there a UNIX command on par with sort | uniq to find string set intersections or "outliers". An example application: I have a list of html templates, some of them have {% load i18n %} string inside, others don't. I want to know which files don't. edit: grep -L solves above problem. How about this: file1: mom dad bob file2:...

grep'ing output from continuously updated output

I'm trying to write a simple script around Lame to customize the program for my specific uses. What I'd like to do is parse out just the percent completeness from the Lame output. Here's what the line looks like now: ./lame --nohist ~/Desktop/Driver.wav ~/Desktop/Driver.mp3 2>&1| egrep -o "\([0-9\%]+\)" But that returns nothing. Here...

Unix 'find' + 'grep' syntax vs. awk

I was using this line to find the phrase, 'B206' within files in the directory I was in and all of its sub directories. find . -exec grep -s "B206" '{}' \; -print It crashes when it tries to read certain files and actually changes the title bar in putty to a bunch of weird characters For example, it crashes all the time when it hits ...

Is there some Unix util that will allow me to grep multiple files with little typing?

Right now I do this a lot: find * | grep py$ | xargs grep foo I recall there is some util that does this with way less typing, but which? UPDATE: I prefer to use the Bash shell if possible. ...

Suppress find & grep "cannot open" output

I was given this syntax by user phi find . | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print $0;}' | xargs grep "B206" I would like to suppress the output of grep: can't open..... and find: cannot open lines from the results.sample output to be ignored: grep: can't open ./cisc/.xdbhist find: cannot open ./cisc/.ssh ...

in vim, how to set "args" to the result of a "grep -l"?

To illustrate, here's how to do it from the command-line: vim `grep "hello" * -Rl` This opens vim with all the files that have "hello" in them (-l gives the filenames alone). I want to do the same thing, but from within vim. Conceptually, something like this (which doesn't work): :args !grep "hello" * -Rl I'm open to completely di...

Using the star sign in grep

I am trying to search for the substring "abc" in a specific file in linux/bash So I do: grep '*abc*' myFile It returns nothing. But if I do: grep 'abc' myFile It returns matches correctly. Now, this is not a problem for me. But what if I want to grep for a more complex string, say *abc * def * How would I accomplish it using ...

How to count number of different IPs that have accessed certain URL from Apache accesss log?

I'm doing something like zgrep "somepattern" access_log.X.gz But I find that a lot of the entries are from the same IP and I'd like to count them as one. ...