grep is a command-line tool for searching text patterns in files.

learn more… | top users | synonyms

2
votes
3answers
84 views

word wrap in ssh session not working with grep

When I ssh to my Linux servers and use grep like this: grep 'timeout exceeded' logfile | less word wrap does not work. However, if I use the same command but use less first, like this: less ...
0
votes
2answers
42 views

Tail, grep and count the instances found in one command?

I am tailing a files output and grepping for lines with certain data. I don't want to output the data to the screen but instead count the number of instances it found and send that to the screen. The ...
38
votes
5answers
51k views

How do I grep through binary files that look like text?

I have binary files that should be text (they're exported logs), but I can't open it with less (it looks ugly - it looks like a binary file). I found that I could open it with vi and I can cat it ...
2
votes
2answers
122 views

How to grep directly to ftp?

What is wrong with this syntax? How to write output directly on remote ftp because lack of space on HDD? This command is working but there is no HDD space to get the full result: find /somedir/ ...
-1
votes
1answer
36 views

How can I visualize a file removing every type of comment if a file (including /* */)? [closed]

I have this small script to visualize config files without the comment lines: cat $1 | grep -Ev '[:blank]*#|^[:blank]*$' | pygmentize -g but it still shows some comments in some files when they have ...
1
vote
1answer
68 views

is it possible to search only a files that have specific extended attributes set?

is it possible to search file in the linux OS that have particular extended attribute as this: ---S--l--- ---S--l--- 1 root root 0 Mar 1004:25/opt/csTuner/iba/wys/tuer_lolk What is S ...
4
votes
6answers
460 views

grep lines after match until the end

I have following output from git status, how do I grep for everything after Untracked files: [alexus@wcmisdlin02 Test]$ git status # On branch master # # Initial commit # # Changes to be committed: ...
1
vote
3answers
1k views

Capture piped multiline grep output into a variable

I'm using Zabbix's zabbix_sender.sh script to push exception stack traces to my remote Zabbix monitoring server. zabbix_sender.sh requires a key and a value for any data that it sends. It can read ...
-1
votes
1answer
25 views

How i can dump raw packets from an existing tcp socket using tcpdump on Mac and Linux? [closed]

Once I know the IP address and port number combo, I can run this to see some of the packets: tcpdump | grep [IPADDRESS] Anybody know how I can now see the raw packets too? Thanks!
2
votes
0answers
20 views

Extracting the date of the latest message from an mbox file

How would I go about extracting the "Date:" header for the latest received message in an mbox file? Note that it's not simply an issue of grep'ing for the latest occurrence of "^Date:", since it ...
0
votes
1answer
18 views

Grep a textfile with (find generated) files, but ignore paths

I receive a huge textfile generated with find. The contents of the generated textfile are a file-referenes with full path, i.e.: //server/dir1/dir1foobar.ext //server/dir1/dir2/dir1bar.ext ...
2
votes
2answers
46 views

Script to email if grep result is null

its been a long time and I cant seem to remember how to do this. I am trying to grep a logfile for a word or words and email if it does not exist in the last fifteen minutes ( I will be setting a cron ...
2
votes
1answer
40 views

how to get the desired value in bash shell from the lshw output?

I want to extract the info from lshw output where it says: -cpu product: ...... I want only the product info of this -cpu. How can I do that with awk or sed?
1
vote
3answers
30 views

How to grep (or other command?) for first instance to last instance in a log?

How does one grep/search a text file so that the results show the first line with the string, and then every other line until the last line with the string? So, if I have a file that looks like this: ...
8
votes
3answers
6k views

How can I handle spaces in file names when using xargs on find results?

One of my common practices is to perform greps on all files of a certain type, e.g., find all the HTML files that have the word "rumpus" in them. To do it, I use find /path/to -name "*.html" | xargs ...
5
votes
5answers
5k views

Grep progress bar using pv (pipe viewer)

I've got a huge directory on my computer and I need to search in every ruby file inside for a string. I could have done it like this : grep -R "string" *.rb but it takes really long and I'd like to ...
1
vote
5answers
349 views

Extracting lines from a file based on prefix

I need to extract all lines from file2 that begin with an id # prefix contained in file1. File 1 is single column like: 324 399 408 135236 321590 File 2 is multi-column like: 1 [tab] 108 [tab] ...
1
vote
5answers
148 views

Get the pid if 2 tomcat(s) is running

I have 2 tomcat's running, how do I get the pid if both have similar names? ps -ef | grep java root 12952 1 0 10:01 pts/0 00:00:03 /usr/lib/jvm/jre/bin/java ...
6
votes
2answers
3k views

How do I show filenames only after a keyword grep search?

I currently have n data files in a directory where each file has at most 1 line of very long data. My directory structure is director/ data1.json data2.json data3.json I know that at ...
47
votes
12answers
63k views

Do you have any useful awk and grep scripts for parsing apache logs? [closed]

I can use log analyzers, but often I need to parse recent web logs to see what's happening at the moment. I sometimes do things like to figure out top 10 ips that request a certain file cat foo.log ...
8
votes
4answers
8k views

Fast extraction of a time range from syslog logfile?

I've got a logfile in the standard syslog format. It looks like this, except with hundreds of lines per second: Jan 11 07:48:46 blahblahblah... Jan 11 07:49:00 blahblahblah... Jan 11 07:50:13 ...
2
votes
2answers
679 views

Sieve: filter subject with regex, file into mailbox named match

I am trying to filter mails by subject with a regular expression. The subjects I want to match are read like [git-foo] some more text where foo is the string I want to check for. I end up with the ...
1
vote
4answers
3k views

grep and tabs: no match

#cat sample 1 -1 2 2 2 2 2 1-1 3 I need to get all the lines that contains negative value, that is 1st line only. Values are tab-separated. First I tried # grep "\-1" sample 1 -1 2 2 ...
6
votes
2answers
6k views

cat * | grep something… what file is the result in?

If one was to run the following command cat * | grep DATABASE the shell would spit out all the lines in * files that contained the word DATABASE in them. Is there any way to also spit out what file ...
2
votes
1answer
121 views

grep ouput filepath with file modified date?

Is it possible to make the grep command to output file paths with file modified date like so: 12-02-2015 /file/path/to/the/file 16-02-2015 /file/path/to/the/file 25-02-2015 /file/path/to/the/file ...
0
votes
2answers
521 views

How to TAIL & EGREP for a specified time range in a BASH script

The subject mostly says it all. I am in charge of a few web servers running Ubuntu 12.04 running Apache2 & I would like to setup APC. Now I understand APC can hit segmentation fault issues when ...
1
vote
5answers
4k views

Don't need the whole line, just the match from regular expression

I simply need to get the match from a regular expression: $ cat myfile.txt | SOMETHING_HERE "/(\w).+/" The output has to be only what was matched, inside the parenthesis. Don't think I can use ...
1
vote
1answer
67 views

Refine grep look behind to avoid numbers

When I query docker images, I get this: #> docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE local/debian 7.5 172c7702a46f ...
2
votes
1answer
189 views

linebreaks between results in grep

I need to occasionally monitor a spider that I have running on my server. I'm testing it to see how many iterations of it are running concurrently and to see if any of them are hanging. I use this: ...
0
votes
1answer
906 views

grep, count and sort iptables log to get IPs qty and DPT?

How can I grep count and sort iptables log to get IPs quantity and DPT? Like I used this oneliner to get top IP quantity. egrep -w "Invalid Packet" ipfirewall.log | grep -o ...
1
vote
1answer
49 views

Finding strings in files with relative path

I don't understand why this two commands don't provide the same result (the differrence is only relative vs. absolute path), can somebody explain it? annika /srv/www/pages/com.example.www/www/povruc ...
8
votes
6answers
6k views

How do i get the default gateway in LINUX given the destination?

I'm trying to get the default gateway, using the destination 0.0.0.0 i used this command: netstat -rn | grep 0.0.0.0 and it returns this list: Destination - Gateway - Genmask - Flags - ...
1
vote
1answer
229 views

How to grep a continuous stream, with paging

I posted this to Superuser but got no takers: http://superuser.com/questions/832578/how-to-grep-a-continuous-stream-with-paging I want to take a log file and filter out some irrelevant log entries, ...
12
votes
3answers
855 views

grep behaving differently on Fedora vs Ubuntu

So when I run this in Fedora I'm seeing this: $ ls hmm_data/indivA12_AATAAG/refs/par1/ 2R-orths.alleles 2R-ref.alleles $ ls hmm_data/indivA12_AATAAG/refs/par1/ | grep -F '-ref.alleles' ...
0
votes
2answers
64 views

Tail grep what tools are for it

I would like to run the following command: tail -f /var/log/syslog | grep -ri 00:16:CB:1E:AF:CA In Linux but it does not working. How would you interactively grep certain text from log files?
13
votes
5answers
3k views

Grepping through .gz log files

Does there exist a magical shell piping which would allow easily to grep through bunch of .gz log files without needing to extract them somewhere? .gz files are Apache logs, result of log rotation. ...
0
votes
0answers
75 views

Nginx - change status code based on grep of process list or similar

We are using nginx as a reverse proxy in our cloud infrastructure, and it's pretty handy. I'd like to use it for something else though. On some of our VMs, there is a process that I need to be able ...
1
vote
1answer
81 views

Regex matching first word and any word

I have a log file with a list of many entries. With grep regex I want to match the first word and another word which can be anywhere in the string. For example, if I specified "user1" the search ...
5
votes
1answer
330 views

screen causes “tail -F | grep” to echo unmatched lines

This is Ubuntu (3.13.0-29-generic #53), trying to do a simple bash script to monitor a log file for matching lines. If I do the following, there is no output in the bash shell except for matches, ...
3
votes
1answer
547 views

Need help grepping postfix log

I'm trying to search for an unknown string (Message ID) in a log based on a known string (recipient address), and then grep the unknown string to output the entire relevant log information. I'm able ...
0
votes
1answer
246 views

Regex matching specific details if first match exists, multiline

I'm struggling to get the correct regex to match specifically 'Contact' and 'User-Agent' only if the 'Contact' address matches 10.0.x.x in ~70GB of SIP messages. The SIP message will always contain a ...
0
votes
2answers
145 views

find and replace multiple files using a file as input to find and another to replace

I need to replace several chunks of text inside some php scripts... i have: find . -name 'products.php' -exec grep --silent 'TEXT_TO_FIND' {} \; -exec ls {} \; -exec sed -i ...
7
votes
2answers
2k views

Grepping for CIDR ranges

From time to time I want to grep CIDR ranges out of my Apache log files. This is easy for ranges that fall on the natural boundaries (/8, /16 and /24) but not so easy for other ranges such as /17 and ...
4
votes
0answers
134 views

grep is inconsistently defaulting to grep -P?

I have a script that does some housekeeping that works perfectly well when invoked from an interactive shell, but did nothing when invoked by cron. To troubleshoot this I started a shell with a ...
-1
votes
2answers
395 views

Parse Apache logs for specific verbiage within the last hour

I'm looking to parse my /var/log/httpd folder which contains a lot of Apache log files. I'm looking for specific events within the last hour. I've tried the below, but I didn't have any luck. grep ...
2
votes
4answers
65 views

Equivalent of grep -l for filenames in zipfile

Given a set of zip files, is there an easy way to list only those zipfiles that contain files whose names match a given pattern, cf. using grep -l to list only files whose contents contain lines ...
0
votes
2answers
275 views

Bash/grep: ignore lines over N characters

I have a find/grep command that i use to search my projects' codebase, thus: find folder1 folder2 folderetc -print | awk '{print "\""$0"\""}' | xargs grep -n "search-string" Something that ...
1
vote
2answers
46 views

How to report filenames found by strings after being piped through grep?

I've been around *nix long enough to remember having done this in the past, and now those neural pathways are gone... I'm searching /usr/local/lib for files that contain img_convert because I'm ...
-3
votes
1answer
154 views

Plesk Unable to exec utility listmng: Cannot find grep program System error 2: No such file or directory [closed]

I have a little problem with my plesk installation at the moment and unfortunately do not have enough knowledge to solve it on my own. I would therefore be glad if I could get a hint on this. I tried ...
1
vote
1answer
461 views

Get some meaning from apache logs with awk and grep [duplicate]

I am trying to have some meaning from my apache log files: I want to parse my access log and have some statistics about 200 status code hits (how many times each of them was hit). So I tried to learn ...