grep

while grep multiple files, how do I stop after first match?

I have a list of patterns in a text file, for which I use bzgrep to match on multiple files: for pattern in $(cat ~/patterns.txt); do echo $pattern; bzgrep -i $pattern *.bz2; done How do I make bzgrep (grep) stop after the first match of the current pattern (I need it stop completely, not stop on the current file being grep'ed) and go...

How to check for tabulator in files?

I would like to check a number of files for the existence of tab characters (ASCII 0x09) in them. (To assert that my sources are tab-free before committing them to repository.) Preferably with standard tools. Of course, grep springs to mind, but apparently grep "\t" file.txt doesn't match...?!? I am aware the answer is probably painfu...

How can I grep for files that have both expressions?

Hello All, I would like to display files that contain more than one expression and exclude files that do not have all expressions. Any ideas? Thanks! ...

grep command to replace multiline text from httpd.conf file on Fedora

Hi, I am a newbie to shell scripting and to Linux environment as well. In my project I am trying to search for following text from the httpd.conf file <Directory '/somedir/someinnerdir'> AllowOverride All </Directory> and then remove this text and again rewrite the same text. The reason to do this rewriting is that the script will b...

getting a long list from grep -l -- is it possible?

I'm performing this grep: grep -l "Validation failed" *.dbg This returns a file listing. However, I'm most interested in the times modified of these files. What would the proper command be? Edit: the argument in the title was wrong. ...

The lines that stand out in a file, but aren't exact duplicates

I'm combing a webapp's log file for statements that stand out. Most of the lines are similar and uninteresting. I'd pass them through Unix uniq, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different user ID, etc. What's a way and/or tool to...

Regex Problem

Take the following contents of a file: "52245" "528" "06156903" "52246" "530" "00584709" What pattern would match both 52245 and 52246 but nothing else? ...

basic grep

I have a large file where each line contains a substring such as ABC123. If I execute grep ABC file.txt or grep ABC1 file.txt I get those lines back as expected, but if I execute grep ABC12 file.txt grep fails to find the corresponding lines. This seems pretty trivial functionality, but I'm not a heavy user of grep so perhaps I...

How do I return only the matching regex when i select-string(grep) in powershell

Hello, I trying to find a pattern in files, but i when i get a match using select-string, i don't want the entire line, i just want the part that matched. Is there a parameter i can specify to do this? Ex: If i did select-string .-.-. and the file contained a line with: abc 1-2-3 abc I'd like to get a result of just "1-2-3" inst...

What's the simplest way to count the number of requests to /foo/ that Apache has served?

I'm looking to retroactively parse the logs and count the number of /foo/* requests that have occurred to have a baseline benchmark for a new feature that we're pushing. A simple command line script would be fine -- with an added bonus for being able to specify a date-range. Some use of grep, perhaps? ...

How to find functions in a cpp file that contain a specific word

Hi all, using grep, vim's grep, or another unix shell command, I'd like to find the functions in a large cpp file that contain a specific word in their body. In the files that I'm working with the word I'm looking for is on an indented line, the corresponding function header is the first line above the indented line that starts at posi...

How to write out an email with mutt, grep the file, then execute a command at new email

I am trying to write a series of scripts that will execute other scripts on my server depending upon text from an email that was just received. I am using mutt as a text based email client, but have no idea where to start for this. I am hoping to understand how this works more than just solving the problem, because this project of mine...

find in files using ruby or python

A popular text editor has the following "find in files" feature that opens in a dialog box: Look For: __searchtext__ File Filter: *.txt; *.htm Start From: c:/docs/2009 Report: [ ] Filenames [ ]FileCount only Method: [ ] Regex [ ]Plain Text In fact, several popular text editors have this. I would...

Can grep (from command line) be set up to highlight the part of the line that matches?

I'm using grep from the command line via cygwin. I'm wondering if there's any way to get it to highlight the part of each line that matches the regex. The closest thing I'm seeing is the -o option, but that only outputs the matching area, and I'd like to see the entire line. ...

Using grep and xargs, avoiding 'unterminated quote' error

Hi, I'm getting frustrated enough that I figured it was time to ask a question. I'm trying to replace an email address across a website that is hard coded into 1000's of pages. It's on a FreeBSD 6.3 server. Here is the command I am using: grep -R --files-with-matches 'Email\@domain.com' . | sort | uniq | xargs perl -pi -e 's/Email\@...

What is the closest thing to grep that comes standard on a Windows install?

I'd like to do something like "dsquery * | grep asdf" on a Windows machine that I can't install anything on. Any ideas? Thank you. ...

How do you grep through code that lives in many different directories?

I'm working on a Python program that makes heavy use of eggs (Plone). That means there are 198 directories full of Python code I might want to search through while debugging. Is there a good way to search only the .py files in only those directories, avoiding unrelated code and large binary files? ...

Preserve ls colouring after grep'ing

If I do $ ls -l --color=always I get a list of files inside the directory with some nice colouring for different file types etc.. Now, I want to be able to pipe the coloured output of ls through grep to filter out some files I don't need. The key is that I still want to preserve the colouring after the grep filter. $ ls -l --color=...

Is comparing string sizes an acceptable alternative to comparing characters?

I'm writing a grep function in C++ (as a self assigned exercise - I realize this doesn't have the functionality of an actual grep feature) to take an original string and the search string you are looking for. In the code, I enter all the characters in a grep string up to the first space it sees. Then I compare the characters in the grep ...

Grep : get all file that doesn't have a line that matches

This may be a duplicate as I believe I already saw something like that but can't find it anymore so I'm asking : I have a lots of files with multiple lines, and in most case, one of the line contain a certain patern. I would like to have every file that do not have a line with this patern. EDIT : Just need to use the "-L" grep option. ...