Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged


You can use grep anyway to search through the file - it does not really care if the input file is really text or not. From 'man grep': -a, --text Process a binary file as if it were text; this is equivalent to the --binary-files=text option. --binary-files=TYPE If the first few bytes of a file indicate that the file contains ...


I guess you could use tail to only output that last 4GB or so by using the -c switch -c, --bytes=[+]NUM output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file You could probably do something with dd too by setting bs=1 and skiping to the offset you want to start e.g. dd if=file bs=1024k skip=12g | grep something


+1 for @jamzed terse answer, however the OP might need some explanation: ps | grep "[d]jango" Using that regex you are launching a process which its ps string will not match itself, since the regexp matches "django" and not "[d]jango". That way you'll exclude the process that has the string "[d]jango" which in this case is grep; The same can be applied to ...


I don't know about using awk instead of grep, but this works for me: tail -f file.log | grep -Ev '(ELB|Pingdom|Health)' EDIT: As dmourati and Caleb pointed out, you could also use egrep instead of grep -E for convenience. On some systems this this will be an link to the same binary, in others a copy of it supplied by the grep package. Either way it lives ...


Pipe it through strings, which will strip out all of the binary code leaving just the text.


There's no reason that's preferable syntax on its own. It's sometimes used as a hack when "grepping" for a process (e.g., ps aux | grep [a]pache). Using that syntax prevents grep from matching its own command line in the process list. See How to prevent "ps" reporting its own process?


$ nc localhost 9571 | awk -F: '/rating/ { print $2 }'


I'm just posting this because some of the comments asked for it. What I end-up using was (15 GB file). It worked very fast and saved me a ton of time. tail -f -c 14G file | grep something I also did a very rudimentary benchmark on the same file. I tested: grep xxx file // took for-ever (> 5 minutes) dd if=file bs=1 skip=14G | grep xxx // ...


ps | grep [d]jango ps | grep d[j]ango ... ps | grep djang[o]


grep -F '-ref.alleles' is equivalent to: grep -F -ref.alleles (none of the characters between the apostrophes are shell metacharacters, so quoting them has no effect.) This is in turn equivalent to: grep -F -r -e f.alleles by normal parsing of - prefixed options. The -e option takes an argument, but -F and -r don't. Since you didn't specify any files ...


Use find ... -print0 | xargs -0 ... e.g. find /path/to -name "*.html" -print0 | xargs -0 grep -l "rumpus" from the find man page -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that ‘-print’ uses). This allows file names that contain ...


You might have a look at zgrep. >$ zgrep -h grep through gzip files usage: zgrep [grep_options] pattern [files]


The zgrep program is available for Linux (and perhaps some Unix too). This will decompress the files and then grep through them.


Try piping it to egrep with a pipe separated lists of words you want to filter out: tail -f log_file | egrep -v 'ELB|Pingdom|Health' Note that using parenthesis around the list of matches is optional. Since the | is treated as a logical OR operator by grep whether it occurs as part of a sub-group or not. '(ELB|Pingdom|Health)' would function exactly the ...


Don't use cat for that. Instead use grep DATABASE * or grep -n DATABASE * (if you want to know the line numbers as well as the filenames) directly. See useless use of cat. To clarify a bit more: cat * actually concatenates all files as it feeds them to grep through the pipe, so grep has no way of knowing which content belongs to which file, and indeed can'...


As far as GNU grep go, this will show you the number of lines before the match: # grep -B number Equivilent for after: # grep -A number You can download GNU Grep here:


This doesn't answer the Title question, but it will do what you are wanting to do. Use tac to reverse the file, then use grep to find your string. If your string only occurs once or a known number of times in the file, then let it run until it finds the known number of occurrences. That way, if your assumption about where it is in the file is incorrect, ...


Use pgrep instead: pgrep -lf django


This would be my approach: find dev -type f -print0 | \ # find all files xargs -0 grep 'extends MY_Output' | \ # search for your string cut -d/ -f2 | \ # extract web folder name sort | uniq # eliminate duplicates Note use of the print0 parameter to find and the -0 (zero) flag to xargs, which prevents ...


You have to escape the regex. ack 'console\.log\(foo' (You should escape the . so that you don't match "consoleflog", because . matches any single character) And if you would rather not do that, do this to quote every metacharacter automatically. ack -Q 'console.log(foo'


There is, unsurprisingly, a tool for this: grepcidr. It is not included by default with any system I'm aware of, but you can download it from here, and it is in both the Ubuntu package repository and the FreeBSD ports collection as well. (Version 2.0 works with IPv6 networks too)


You do not need to use xargs, because find can execute commands itself. When doing this, you do do not have to worry about the shell interpreting characters in the name. find /path/to -name "*.html" -exec grep -l "rumpus" '{}' + from the find man page -exec command {} + This variant of the -exec action runs the specified command on the selected ...


pv operates on pipes (not commands) -- It is a volume gauge showing how much data has gone past a given point in the pipeline. Your grep command is not a pipeline (| - the pipe operator is nowhere to be found) - it's just a single command doing its thing. pv can't help you here, you just have to trust that grep is actually doing its thing on all of the ...


With GNU grep (tested with version 2.6.3): git status | grep -Pzo '.*Untracked files(.*\n)*' Uses -P for perl regular expressions, -z to also match newline with \n and -o to only print what matches the pattern. The regex explained: First we match any character (.) zero or multiple times (*) until an occurence of the string Untracked files. Now, the part ...


Use awk as follows: $ echo '*EXTRA File 78223 C:\foo.pdf' | awk '$3 > 1048576 {print $0;}' $ echo '*EXTRA File 78223 C:\foo.pdf' | awk '$3 > 40000 {print $0;}' *EXTRA File 78223 C:\foo.pdf


Quanta beat me to it, but I'll include a sed variant if you're that way inclined: nc localhost 9571 | sed -ne 's/^rating://p' Ditto what MadHatter said, though. Your current solution is perfectly sound. (Although I'd grep for "^rating:" rather than just the word to ensure you only get the line you want.)


My answer is a variation on the typical answer for searching for "foobar" in a ps listing. The argument of "-A" "ps" is more portable than "aux", I believe, but this change is irrelevant to the answer. The typical answer looks like this: $ ps -A -ww | grep [f]oobar Instead I use this pattern: $ ps -A -ww | grep [^]]foobar The main advantage is that it's ...


This happened because the first thing > does is to create the file it wants to write to - and if the file already exists, its contents will be deleted. (Also, there's no need at all to use cat in your statement since grep works on files, not just on STDIN.) The correct way to do this is to use a temporary file either to read from or to write to. So ...


If you don't mind using sed, here is a possible solution git status | sed -n -e '/Untracked files/,$p'


Oh wait, this works: ps | grep django | grep -v grep

Only top voted, non community-wiki answers of a minimum length are eligible