Tag Info

Hot answers tagged


+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 ...


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 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 ...


You can do pretty much anything with apache log files with awk alone. Apache log files are basically whitespace separated, and you can pretend the quotes don't exist, and access whatever information you are interested in by column number. The only time this breaks down is if you have the combined log format and are interested in user agents, at which point ...


The command you are looking for is strings Its name is quite self-explanatory, it retrieve any printable string from a given file. man strings gives: STRINGS(1) NAME strings - find the printable strings in a object, or other binary, file SYNOPSIS strings [ - ] [ -a ] [ -o ] [ -t format ] [ -number ] [ -n number ] [--] [file ...]


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


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?


You can use nmap to run a ping scan. nmap -sP 192.168.254.* Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-09 11:32 GMT Host xyzzy.lan ( is up (0.00022s latency). MAC Address: 00:0C:29:5B:A5:E0 (VMware) Host plugh.lan ( is up (0.00014s latency). MAC Address: 00:0C:29:2E:78:F1 (VMware) Host foo.lan ( is up. ...


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 ...


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


My version of GNU Grep has a switch for this: grep -R foo --include '*.txt' * "--include=GLOB Search only files whose base name matches GLOB (using wildcard matching as described under --exclude)."


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


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


You could try grep pattern file | tail -1 or tac file | grep pattern | head -1


One thing I've never seen anyone else do, for reasons that I can't imagine, is to change the Apache log file format to a more easily parseable version with the information that actually matters to you. For example, we never use HTTP basic auth, so we don't need to log those fields. I am interested in how long each request takes to serve, so we'll add that ...


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: http://www.gnu.org/s/grep/


Another way is {grep ...; bzgrep ...} >file && has the difficulty that the bzgrep wouldn't be run if the grep failed.


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 ...


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


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 ...


This is actually dependent on your shell. Quotes (either kind) are primarily meant to deal with whitespace. For instance, the following: grep hello world file1 will look for the word "hello" in files called "world" and "file1", while grep "hello world" file1 will look for "hello world" in file1. The choice between single or double quotes is only ...


How about this: $ tail -f logfile? And if you need to grep: $ tail -f logfile | grep foobar.


The -l argument should do what you want. -l, --files-with-matches Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)


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 ...


locate filename Much faster than find, if you're running the locate service, and it only finds files that existed at the time updatedb last ran (usualy the night befor under the control of a cron job). You can run updatedb by hand, but that is even slower than the find cletus suggests, and requires root. I sometimes update the database by hand after ...


I consider myself a regex noob, but I created a bunch of files with variable length strings in them and I think I got what you wanted, try this: user@host$ grep -e '[^\ ]\{7,\}' * For those who don't quite understand this: -e makes grep search using a regex. [^\ ] means to match a single character except space. \{7,\} means to match a string of 7 or ...


$ ip -o addr show | awk '/inet/ {print $2, $3, $4}' lo inet lo inet6 ::1/128 eth0 inet eth0 inet6 fe80::2a0:feed:dead:beef/64


Use pgrep instead: pgrep -lf django


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.)


Use nmap. Important to run it as root so you get the MAC addresses. Example: sudo nmap -sP Will scan - Look up CIDR notation on wiki if you're not familiar with this subnet notation. You should be able to get nmap from the repos of any recentish Linux distro, e.g. sudo apt-get install nmap or sudo yum ...

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