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
3 answers

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. I need to find out if all these emails were sent…
gAMBOOKa
  • 999
  • 6
  • 19
  • 34
0
votes
2 answers

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 /etc/redhat- redhat-lsb/ redhat-release …
Yousui
  • 245
  • 3
  • 4
  • 9
0
votes
2 answers

Display specific word in file. To be used as varible, grep for email in log

I'm looking to display just the email address in the /var/log/secure file. The email goes into a variable, so just grepping for lines won't work. I know how to string together sed commands, but is there a cleaner way? I could even scrap the idea…
J. M. Becker
  • 2,471
  • 1
  • 17
  • 21
0
votes
2 answers

tee and grep at the same time (shell)?

I'm trying to run a server that writes to $log (a txt file) and then find all the text in the logfile that starts with [1] and put it in another file. Here's my attempt. tee -a $log works along with everything else. The grep command doesn't though.…
dukevin
  • 1,630
  • 3
  • 18
  • 25
0
votes
3 answers

AWK - Is it possible to search for pattern, then sort results based on a wildcard?

I am storing a number of individually serialized PHP arrays to a file. Each line of the file contains one serialized array. For example: a:2:{s:4:"name";s:8:"John Doe";s:3:"age";s:2:"20";} a:2:{s:4:"name";s:8:"Jane…
tambler
  • 131
  • 1
  • 5
0
votes
1 answer

Following a file mixed with grep to exclude lines

Basically I want to combine the function whereby you can Less a file and then Shift+F to follow the file, as you would do with Apache's access.log. However I would like the output to ignore/hide certain lines such as lines with .jpg in or lines…
DanH
  • 827
  • 2
  • 9
  • 26
0
votes
2 answers

grep -r pattern ./ without recursion?

I want to run the grep -r pattern ./ but WITHOUT recursively going through the sub directories. When I removed the -r flag, I didn't get any output in my terminal. What flag am I supposed to use to grep for patterns in files in my current…
John
  • 7,343
  • 23
  • 63
  • 87
0
votes
1 answer

Move all images in folder to subfolder, and update all references to those images to their new location?

I have a folder which contains a ~50 text files (PHP) and hundreds of images. I would like to move all the images to a subfolder, and update the PHP files so any reference to those images point to the new subfolder. I know I can move all the images…
Professor Frink
  • 529
  • 4
  • 7
  • 15
0
votes
4 answers

how to find a text string which may be present in some unknown file in entire filesystem

I am stuck up with a problem I have a line 'something' in some file. In which file is this line that I have forgotten. In the entire root file system I would like to find out which file and where is this line. So how can I go for this.I have used…
Registered User
  • 1,463
  • 5
  • 18
  • 37
0
votes
2 answers

How to strip logfile with grep to remove various dispensable information?

My logfile has the following format: Dec 26 13:11:48 192.168.1.1 kernel: ACCEPT IN=br0 OUT=vlan1 SRC=192.168.1.2 DST=74.125.43.147 LEN=44 TOS=0x00 PREC=0x00 TTL=63 ID=9312 DF PROTO=TCP SPT=11733 DPT=80 WINDOW=5840 RES=0x00 SYN URGP=0 OPT (020405B4)…
NES
  • 215
  • 2
  • 8
0
votes
2 answers

Search multiple strings from multiple files

How to search multiple strings from multiple files with a single command. May be using grep or find or if there is any other in Linux or Solaris
Ramesh Kumar
  • 1,770
  • 5
  • 19
  • 29
0
votes
2 answers

Recover programmation source files

I've source code files (Java and C++) to recover from a broken RAID 1+0 array, I've been able to access the virtual drive with an other server but the ReiserFS partition can't be recovered with ReiserFS tools. I've made a binary image of the…
0
votes
1 answer

Egrep Regular Expression to suppress certain lines

i try to use the following command to suppress certain lines of output that contain the strings "DST=192.168.1" or "DST=192.168.2" tail /var/log/messages | egrep -v -e 'DST=(192\.168\.1\.1)|DST=(192\.168\.2\.1)' My Regex doesn't work, can someone…
user56548
0
votes
1 answer

How to display results without two first lines

When I run some bash command it returns 2 .. n lines of text (n is different each time, may contain blank lines). How to filter the output to display the result skipping lines 1 and 2? e.g. $ my_command file1 file2 file3 file3 $ my_command |…
takeshin
  • 1,471
  • 3
  • 21
  • 28
0
votes
3 answers

How to filter http request URL by mime type?

I'm trying to make a shell script which filters http request URL by mime type. (ex: image/jpg image) I used tcpdump to sniff packets and grep to filter http headers. This is my current command: echo | sudo -S tcpdump -vvAtp -i en5 tcp…
Eonil
  • 10,459
  • 16
  • 36
  • 54