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
0
votes
1 answer

shell script to grep within range inside of cron

I'm trying to create a shell script that would look for ERROR inside of /var/log/jbossas/standalone/server.log, such as following: # grep ERROR /var/log/jbossas/standalone/server.log 10:36:37,530 ERROR [class X] (ajp-/192.168.X.X:8009-20) THIS IS A…
alexus
  • 13,112
  • 32
  • 117
  • 174
0
votes
1 answer

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 in the permissions: S - the changes are written…
maihabunash
  • 443
  • 1
  • 11
  • 25
0
votes
1 answer

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,…
0
votes
2 answers

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?
naturelle
  • 1
  • 1
0
votes
0 answers

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 to confirm is running. Ideally, I'd like to have…
SamBarham
  • 143
  • 1
  • 1
  • 4
0
votes
2 answers

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 's/TEXT_TO_FIND/REPLACE_TEXT/g' {} \; this work, but i have text of about 2…
0
votes
2 answers

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 irritates me regularly is minified javascript & css files,…
Max Williams
  • 237
  • 1
  • 3
  • 14
0
votes
1 answer

How to comma-demilit the output from cut?

So far, I have this: grep -B 36 'pattern1' Mapper.1.Configuration.MapRules | grep "pattern2" | cut -d'"' -f2 which give me a new-line delimited list of values that I need. I could put this into a file and then do a find and replace of all new-lines…
Ramy
  • 117
  • 1
  • 8
0
votes
2 answers

Invalidating email addresses from sql dump before import

Synopsis I would like to import production data into the development environment so testing can be done in an almost accurate way. Of course I need to invalidate e-mail addresses as I don't want e-mails reaching the end-user. Source Just a side note…
Ash
  • 471
  • 1
  • 4
  • 14
0
votes
1 answer

Is there a tool for indexing a directory in order to perform cheap content search? (hashing by word, for example)

I am often using grep -R on an entire directory tree to find all files that contains a specified word. I wonder if there is a tool that makes the whole operation much faster, maybe via hashing? (Unix systems!). Even better if it exists to optimize…
fstab
  • 111
  • 3
0
votes
1 answer

indexing logs for fast repeated grep/search

I have sets of verbose logfiles that in the course of solving a problem, I will repeatedly regrep. I usually have about 1-10GB sets of 50-150 files, that I'll spend a few hours with and then never look at again. Even with an SSD and lots of RAM it…
mhb
  • 103
  • 3
0
votes
2 answers

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 . I'm looking for a generic shell command which would able to read the headers of the most common image…
Fox
  • 992
  • 2
  • 14
  • 23
0
votes
2 answers

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:
Matt Bear
  • 874
  • 3
  • 12
  • 28
0
votes
2 answers

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/cron/jobs# ps -ef | grep *.php | grep -v grep THANKS!
Slinky
  • 1,027
  • 3
  • 15
  • 26
0
votes
1 answer

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 total | awk '{print $2}' | sed 's/K//' | awk '{SUM +=…
jfreak53
  • 163
  • 1
  • 4
  • 27