Questions tagged [grep]

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

The grep utility searches a pattern (regular expression) in a text file. There are many options to control how matches are performed and how to display matches.

External references

Tutorials

Further reading

See also grep on Unix & Linux Stack Exchange for more detailed reading.

326 questions
1
vote
2 answers

Deleting inserted content in multiple files on linux server

I often have problem with sites that get hacked. Usualy they end up with inserted script in different files. Is there a way, on linux, to search for this content and automaticaly delte it ? Usualy this content starts with, and ends with something…
Pracovek
  • 33
  • 1
  • 2
  • 6
1
vote
1 answer

Centos locate file in binary file

I have ran a command to find a string in files on the server like this: cd / grep -r "string to be found" * And the server returned some results like this Binary file dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0-part1 matches Binary file…
Mike
  • 113
  • 1
  • 1
  • 9
1
vote
4 answers

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: $ qemu-img info…
curtis
  • 184
  • 1
  • 7
1
vote
2 answers

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 will exclude the grep svn from being included in…
user160910
1
vote
2 answers

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

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. :) Example output: Schedule: blabla: blabla: …
Bernard
  • 19
  • 2
1
vote
3 answers

SED Find & Replace w\ Regular Expressions

Alright, So i'm confused & out of ideas. I'm trying to replace all the old IP addresses with a new one. find -type f | grep \.php$ | xargs sed -r -i "s/(\'|\")(localhost|127.0.0.1|10.0.32.4|10.0.32.5)(\'|\")/\"10.0.32.165\"/g" I'm trying to find,…
grufftech
  • 6,760
  • 4
  • 37
  • 37
1
vote
2 answers

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?
user160910
1
vote
1 answer

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
  • 185
  • 1
  • 5
1
vote
4 answers

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 end_log_pos 487 Xid = 79514636 COMMIT/*!*/; # at…
alexus
  • 13,112
  • 32
  • 117
  • 174
1
vote
1 answer

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 search starting from root directory, assumes that…
Martin
  • 352
  • 3
  • 12
  • 29
1
vote
1 answer

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 | grep 'Summary:' so that grep start to output…
JMW
  • 1,463
  • 4
  • 19
  • 27
1
vote
2 answers

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]*\.[0-9][0-9]*\.[0-9]*' | sort | uniq -c | sort -r…
ADM
  • 1,373
  • 12
  • 16
1
vote
2 answers

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
  • 5,328
  • 19
  • 64
  • 84
1
vote
2 answers

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 name. Apparently the $ sign is causing the error,…
Yon
  • 258
  • 1
  • 3
  • 8
1
vote
1 answer

How to grep string in perl

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 "2 active Sessions, 0 passivated Sessions (more…
Arun
  • 13
  • 1
  • 4