Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
0 votes
2 answers
105 views

Looking for a shell command to read non-binary part of most common image types

A website I'm hosting on my dedicated server has been hacked. Some pictures have been infected with things like <?php eval(base64_decode(....));?>. I'm looking for a generic shell command which ...
Fox's user avatar
  • 1,062
0 votes
2 answers
820 views

GREP find and use SED to replace string on all files

One of our old hosted Joomla sites suffered a JavaScript injection, and im going through cleaning it up. The following code was inserted into every .php or .js file: <? #0c0896# echo " <script ...
Matt Bear's user avatar
  • 874
1 vote
4 answers
3k views

Using grep -Po to extract regex

I've been struggling with "grep -Po" off and on for a couple hours. What I would like to do is to find out how many bytes the virtual disk size is as reported by qemu-img info. Here's example output:...
curtis's user avatar
  • 184
0 votes
2 answers
563 views

Getting Running Script Names Via PS

I need to get a list of all running PHP scripts but piping PS thru grep just gives me a list of all references to PHP files How do I accomplish this? Is this even possible? root@myhost:/var/www/...
Slinky's user avatar
  • 1,057
1 vote
2 answers
678 views

Why does grepping ps [p]rocess_name exclude grep from the results

A cool trick that saves you from having to use grep -v when grepping ps output (yes I know pgrep exists) is to put the first letter of the process into a character class like ps -ef |grep [s]vn. This ...
user avatar
14 votes
2 answers
21k views

How to find files that don't contain a given search string

I have a command that finds all the PDF files that contain the string "Font" find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -H 'Font' '{}' ';' How can I change this command such that it ...
Slinky's user avatar
  • 1,057
0 votes
1 answer
477 views

Finding out total PHP usage in MB's

I'm trying to find out total memory used by all PHP processes on my CentOS server. After some grepping and awking this is my final command. ps -e | grep php | awk '{print $1}' | xargs pmap | grep ...
jfreak53's user avatar
0 votes
2 answers
292 views

Grep first number value from quota -u

I would like to get first number from: [root@nowosci /]# quota -u testclient Ograniczenia dyskowe user testclient (uid 7798): System plików bloki miękki twardy pobł. pliki miękki twardy pobł. ...
Spacedust's user avatar
  • 568
1 vote
2 answers
1k views

I want to filter out two lines from the output of a program [closed]

I have a command that outputs a bunch of data, but I only want two lines. Grep doesn't work because the lines I want are not next to one another. I can't seem to figure out sed... Help please. :) ...
Bernard's user avatar
  • 19
1 vote
2 answers
1k views

The meaning of * in Basic regex versus Extended regex

I thought * meant zero or more of the character or class that precedes it in basic or extended regex. Why does echo hello| grep '*llo' fail but echo hello |egrep '*llo' succeed?
user avatar
0 votes
2 answers
1k views

Testing if a server is up with curl and grep. Grep adds headings?

Hi I'm trying to see if a server I'm running has been stopped (if it has, it returns a 502 Bad Gateway message.) So I tried to do this : curl http://MY_URL | grep "502" The curl part returns what ...
interstar's user avatar
  • 1,321
0 votes
2 answers
765 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 ...
Giacomo1968's user avatar
  • 3,561
0 votes
2 answers
388 views

grep double quote in cron

i run this command on the terminal $ my_json_generator.rb | grep \"mtype\":164 | my_json_consumer.rb json_generator creates json objects. 1 per line. {"foo":7, "mtype":164, "bar":[1,2,3]} I only ...
Poul's user avatar
  • 101
1 vote
1 answer
2k views

find and delete files of a certain type inside a tar.gz file

Is there a way to not only find but also delete any .gz files inside a .tar.gz file? I found this link but I wouldn't know how to modify it to make it able to delete found files.
Obay Ouano's user avatar
4 votes
3 answers
22k views

How can I count the number of lines matching a pattern returned from a linux command

How can I count the number of lines matching a pattern returned from a linux command I want the number of lines returned beginning with 'foo' , so if I pipe the output to grep will this ...
Dave's user avatar
  • 377
0 votes
1 answer
652 views

grep to IP address when IP address in parameter

I need to grep to IP address ( as the following example ) , I use ksh script , # ifconfig -a | /usr/xpg4/bin/grep "100\.106\.2\.120 " inet 100.106.2.120 netmask ffffff00 broadcast 100....
yael's user avatar
  • 2,473
0 votes
1 answer
424 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 ...
Luke B's user avatar
  • 101
1 vote
4 answers
2k views

greping multiple lines from MySql binlog

I have binlog from MySQL and I need to output certain time frame into a seperate file, how would I do that? here is sample of what binlog file contains: # at 460 #130120 0:09:17 server id 1 ...
alexus's user avatar
  • 13.4k
0 votes
2 answers
1k 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 ...
shantanuo's user avatar
  • 3,619
0 votes
1 answer
533 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 ...
yael's user avatar
  • 2,473
3 votes
2 answers
8k 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 ...
Itai Ganot's user avatar
  • 10.8k
0 votes
3 answers
794 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 main.cf....
yael's user avatar
  • 2,473
-4 votes
3 answers
101 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 ...
Pete Mancini's user avatar
2 votes
1 answer
434 views

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

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 die....
doub1ejack's user avatar
1 vote
1 answer
1k 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 ...
Martin's user avatar
  • 372
3 votes
2 answers
1k 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' ...
carpii's user avatar
  • 561
1 vote
1 answer
51 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 | ...
JMW's user avatar
  • 1,473
2 votes
3 answers
521 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 SCSI,...
Lance Woodson's user avatar
0 votes
1 answer
433 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 ...
Jason's user avatar
  • 11
19 votes
1 answer
582 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
hortitude's user avatar
  • 565
0 votes
3 answers
3k 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 ...
Mike B's user avatar
  • 12k
13 votes
2 answers
13k 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 ...
Ladadadada's user avatar
  • 26.8k
1 vote
2 answers
3k 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 '[0-9][0-9]*\.[0-9][0-9]*\...
ADM's user avatar
  • 1,393
3 votes
1 answer
412 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, ...
dukevin's user avatar
  • 1,630
6 votes
4 answers
4k 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).
DD.'s user avatar
  • 3,114
1 vote
2 answers
3k 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.
Justin's user avatar
  • 5,438
5 votes
4 answers
12k 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 ...
user548971's user avatar
8 votes
2 answers
10k 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 ...
HNygard's user avatar
  • 183
0 votes
1 answer
704 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 ...
danny's user avatar
  • 123
2 votes
2 answers
294 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 ...
Harry's user avatar
  • 128
4 votes
3 answers
605 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?
numan's user avatar
  • 143
1 vote
2 answers
908 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 ...
Yon's user avatar
  • 258
1 vote
1 answer
8k 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 ...
Arun's user avatar
  • 13
2 votes
2 answers
4k 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': []} [2012-...
Steve Bennett's user avatar
0 votes
2 answers
391 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 ...
TecBrat's user avatar
  • 183
3 votes
4 answers
5k 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 ...
Ahmed Laatabi's user avatar
3 votes
2 answers
4k 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, ...
CamelBlues's user avatar
1 vote
1 answer
117 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. How ...
Stole's user avatar
  • 111
63 votes
8 answers
24k 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 bin/...
Steve Bennett's user avatar
16 votes
1 answer
8k 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 ...
tester's user avatar
  • 565

1 2 3
4
5
7