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

learn more… | top users | synonyms

0
votes
2answers
491 views

remove non-printing characters

I have a tab delimited text file. When I open the file with vi editor, I can see ^M character (in blue color). This is not part of my data. It got there because the original SQL data had carriage ...
0
votes
1answer
153 views

grep + match value only if value in the end of line

please advice what is wrong with my code, ( I run this code on both OS linux and solaris ) I don't get the line from: "file ended with .tmp" example: I need to verify if $FILE ended with .tmp ...
3
votes
2answers
2k views

Is there a way to find a specific word in all files/folders in Linux?

I usually use grep word * while being in a folder which includes files that have that word. But in this folder i also have folders which under them there are files that have that word, what is the ...
0
votes
3answers
218 views

grep + Regular Expressions to match uniq number

My target is to verify if $FILE is a backup file ( backup file ended with xxxx.xx.xx.xx number Example of backup files ls /etc/VRTSvcs/conf/config main.cf.17Dec2012.09.10.14 ...
-4
votes
3answers
71 views

grep only returns help text [closed]

Well, I am perplexed. I am working with an Ubuntu server and I type in grep 'bash' *.sh BUT fgrep 'bash' *.sh works like a champ. which grep and which fgrep both point to their respective ...
2
votes
1answer
115 views

finding files that match a precise size: a multiple of 4096 bytes

I have several drupal sites running on my local machine with WAMP installed (apache 2.2.17, php 5.3.4, and mysql 5.1.53). Whenever I try to visit the administrative page, the php process seems to ...
1
vote
1answer
306 views

recursive grep started at / hangs

I have used following grep search pattern on multiple platforms: grep -r -I -D skip 'string_to_match' / For example on FreeBSD 8.0, FreeBSD 6.4 and Debian 6.0(squeeze). Command does a recursive ...
3
votes
2answers
243 views

Extracting a line section of mysql backup using sed

I occasionally need to extract a single record from a mysqlbackup To do this, I first extract the single table I want from the backup... sed -n -e '/CREATE TABLE.*usertext/,/CREATE TABLE/p' ...
1
vote
1answer
35 views

start output from first match

i have a command that prints out some statistical information that looks like this: Detailed Hardware Status Dump: ... Summary: Memory info: OK HDD info: OK ... I'd like to ./dump_hw_status | ...
2
votes
3answers
114 views

grep pattern interpretted differently in 2 different systems with same grep version

We manufacture a linux appliance for data centers, and all are running fedora installed from the same kickstart process. There are different hardware versions, some with IDE hard drives and some ...
0
votes
1answer
295 views

Grep /var/log for hacker/script kiddy activity and e-mail?

CentOS 6 Apache Server version: Apache/2.2.15 (Unix) Thinking about how to automatically, once a day, grep all the logs in /var/log/httpd for hacker, phishing, etc activity and e-mail it to myself so ...
18
votes
1answer
455 views

Why bracket a single letter in a grep regex?

I've seen several instances where people are doing this: grep [f]oobar But I don't understand why that is preferable to grep foobar
0
votes
3answers
996 views

How can I grep for two values from the same input being piped to it?

CentOS 5.x I'm trying to build a shell script that searches data provided via stdin. Here's an example of the input stream: Date: 1/1/11 Time: 12:00 AM Foo: 12345 Foo1: dskjflsdkjflksdjlfds ...
6
votes
2answers
1k 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 ...
0
votes
1answer
713 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 ...
3
votes
1answer
267 views

grep recursive exclusive search

I have text I want to recursively search in mydir/. I would normally type grep -r "text to find" mydir/" but what would I type if I wanted to search all the files except a specific one? For example, ...
6
votes
4answers
765 views

Kill process by command name

I would like to kill a java process based on the command name... Whats the best way to do it? (i.e. when you do ps -f the name in the CMD column).
1
vote
2answers
90 views

Delete All Files Matching Pattern In Directory

How can I delete all files containing -20 in the filename in the current directory? I have ls | grep "-20" | rm -rf But that does not work. Ideas? Thanks.
4
votes
3answers
5k views

iptables - Clear all PREROUTING rules with a specific destination address

I have a script that adds iptable PREROUTING rules. They all have the same to address. When I run this: iptables --list PREROUTING -t nat I see output like this: DNAT tcp -- anywhere ...
3
votes
2answers
1k views

Cron job checking for changes in Git repository

We have just moved our server configs to a Git repository. Therefore there should not be any changes in any of the repository folders. I was thinking about how I could set up a cron job to check for ...
0
votes
1answer
324 views

puppet master --compile logs errors to stdout

I see a bug about this that was accepted and then closed a year ago: http://projects.puppetlabs.com/issues/3670 but I'm using puppet 2.7.14 and am getting the same issue. I'm trying to use "puppet ...
2
votes
2answers
158 views

Gathering IP's from a complicated log

I have a question regarding the use of some more advanced grep, awk, sed. I have a log file, for a proprietary MTA, that contains IP's in a string, delimited by [redacted]^~x.x.x.x^[redacted]. So far ...
4
votes
3answers
368 views

Is there a way to grep with a constrained file type?

right now i am using something like this: find . -name "*.xml" | xargs grep -l "foobar" it works, but i was wondering if grep has this functionality built in?
1
vote
2answers
121 views

Odd error with regular expression in grep

I'm running the following command: cat something | egrep "(abc|def)$" On a server running Linux. The same OS with kernel 2.6.18 gives the correct answer, while with 2.6.19 I get: Illegal variable ...
1
vote
1answer
1k views

How to grep string in perl [closed]

How to grep the string in perl. Variable sessionWeb contains a web page html code. I want to grep "active Sessions" from this and want to print as below. For example the line in the web page will be ...
1
vote
2answers
913 views

Grep to find lines starting at pattern A until pattern B is matched

I have a log that contains bits like this: [2012-04-16 15:16:43,827: DEBUG/PoolWorker-2] {'feed': {}, 'bozo': 1, 'bozo_exception': URLError(error(110, 'Connection timed out'),), 'entries': []} ...
0
votes
2answers
273 views

Find text, then insert linebreak and some php code across multiple files

I have a certain php code comment that appears in about 75 files across several users. This command succsessfully locates it. (I didn't bother looking for the double slashes because I wasn't sure ...
2
votes
4answers
2k views

bash : “set -e” and check if a user exists make script exit

I am writing a script to install a program with Bash. I want to exit on error so I added set -e to the beginning of my script. I have to check if a user exists inside of my script. To do this I am ...
2
votes
2answers
814 views

Grepping through the results of apachectl -S

I have a server with about 300 virtual hosts. When I want to make sure a specific httpd.conf file is loaded into the Virual Host config and the syntax is correct, I run apachectl -S. The problem is, ...
1
vote
1answer
101 views

Regular expressions in GREP [closed]

I have an .xml file. The tags inside are: <Info>Product</Info> Now, I have 20 000 tags like this in the file. One tag however, starts properly but it is missing a proper closing tag. ...
33
votes
5answers
5k views

How to prevent “ps” reporting its own process?

$ ps | grep django 28006 ttys004 0:01.12 /usr/bin/python bin/django celeryd --beat 51393 ttys005 0:01.45 /usr/bin/python bin/django celeryd -l INFO 51472 ttys005 0:01.29 /usr/bin/python ...
6
votes
1answer
1k views

Ack search for literal strings [closed]

I am sick of having to escape things when I want to search for part of an html tag. How can I ack search for exactly what I type without having to escape stuff? e.g. ack-grep 'console.log(foo' I ...
2
votes
3answers
192 views

How do I make grep results colored?

I have some output of my program: # php check.php | grep -E "rule_1|rule_4" I would like results equaling to rule_1 to be red and results equaling to rule_4 to be blue. Is this possible, because at ...
0
votes
4answers
2k views

solaris + grep syntax in solaris

my target is to match Exactly the string snmpmanager from hosts file on solaris & linux the following command work on Linux (red-hat 5.1) but not for SunOS , please advice how to fit the syntax ...
6
votes
2answers
836 views

Can I run grep against a zOS dataset via Unix system services?

I have a search I'd like to run against a zOS dataset, and I know how to form the grep command. I have access to the machine via Unix system services, how to I address a dataset from that ...
2
votes
2answers
204 views

egrep not working in crontab

I have a simple bash script wich works fine when running in command line, but not in crontab: #!/bin/bash PATH=/usr/bin:/bin for f in /data/home/cwolff/tmp/*access_log*.txt; do egrep "r:[A-Z]+ ...
0
votes
4answers
2k 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 ...
0
votes
1answer
1k views

How to find a file that contains the specified string in FreeBSD?

I'm searching for the way to find a file that contains specified string text. It should be fast as possible but its not that important. I was reading the manual, and I've build something like that: ...
1
vote
4answers
132 views

GREP show lines that contain this but not that

I would like to search for lines that contain "uploaded" but do not contain "09" Is there a way to do this with grep? (CentOS 5.6 if it matters).
5
votes
4answers
4k 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 ...
0
votes
3answers
486 views

tool to analyse/grep log files

Is there any web based GUIs to analyse or in realtime filter/grep log files from apache? log files that are access logs or error logs or postfix logs etc. Edit: I don't mean traffic analysis. Much ...
0
votes
1answer
765 views

Ubuntu command to constantly monitor a service?

I was curious if anyone new a command like tail or top to constantly monitor a service as it runs. I'm trying to watch sendmail currently to see who is connecting to it, but would like to have it a ...
0
votes
1answer
32 views

Compare/Calculate like files

I have program generating reports on a regular basis. These reports are follow a simple and consistent format (specifically, these are "OProfile profiling reports). Each line's format is: ...
0
votes
3answers
413 views

grep out unique senders from a huge list of emails

I just found a huge list of emails under my user account in Centos /home/user/mail/new I opened some of them and noticed they were sent from a particular cron job. From address is root@hostname.com. ...
0
votes
2answers
525 views

How to update my grep utility on CentOS 5.6?

I'm using a CentOS 5.6 system. Since there is a bug in my version of grep. I want to upgrade to a new version. I tried to use yum to update(upgrade) it, but failed. [root@localhost ~]# cat ...
1
vote
2answers
4k views

How to grep httpd error_log within a time range?

How can I grep only lines from a huge (120GB) httpd error_log based on a time range, say: from 2011-11-15 11:30 pm to 2011-11-16 01:30 am Thanks!
4
votes
4answers
158 views

Possible to use grep simply for finding files in a directory structure?

I like using grep but sometimes I just want to search for the names of files in a directory tree, but don't want grep to open the files and search inside them. Can grep do this?
23
votes
4answers
33k 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 ...
1
vote
5answers
277 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] ...
6
votes
3answers
233 views

OS/2 grep had a great feature where it would show you n lines BEFORE the search item was found. Is there an equivalent in unix anywhere?

Solaris would be preferable, but I'll take linux or something I can compile. Does such a beast exist?