Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [grep]

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

0
votes
1answer
55 views

Linux Shell script - grep . filename

Can some explain the meaning of grep . filename, what does the . (dot) means here.? Actually it removed all the empty lines in my file. I just want to know how it's working.
2
votes
1answer
17 views

Cygwin 2.9.0 cat/tac Commands Fail on Large Files when Piping to grep -q -m1

I am seeing some odd behavior using Cygwin x64 2.9.0 on Windows 10 Pro x64. The command I am attempting to run is the following: tac <file> | grep -q -m1 -F "literal string" The above command ...
1
vote
2answers
63 views

Send email if script outputs string

I found this line: sh script.sh | grep 'NO' 2>&1 > grep.log && /usr/bin/mail -s "grep found something" m@mail.com < grep.log which will write the output of script.sh to grep.log ...
0
votes
0answers
31 views

rsync + find & replace string on all incoming files

I am using rsync to sync my development server with my production server. To make things easier, how can I pipe all the files so that all instances of a string are replaced with another during the ...
0
votes
2answers
92 views

Any way to avoid using `grep -v`

When performing a grep filtering across pipes, as in the following example, $ ps -ef | grep 24604 username 18660 24604 0 16:38 pts/3 00:00:00 ps -ef username 18661 24604 0 16:38 pts/3 ...
0
votes
1answer
108 views

Grep returns nothing

This is the grep command I used grep -ic address log* The output is 0. I know for a fact that there are more than 60 occurrences of the word address in the log file. But I still get 0. Now, I ...
0
votes
1answer
263 views

How can I use an iperf output and only grep Interval and Bandwidth?

I am trying to get the output from the command iperf -c 10.0.0.1 -t 3600 -i 2 And only need the Interval and bandwidth fields listed for the entire hour of logging. I haven't used grep or awk in ...
-1
votes
1answer
29 views

Apache Logs - identify IP that made series of specific requests

Given the following apache access log: 127.0.0.1 - - [04/May/2018:11:19:03 +0300] "GET /file1 HTTP/1.1" 200 ... 127.0.0.1 - - [04/May/2018:11:19:03 +0300] "GET /file1 HTTP/1.1" 200 ... 127.1.1.1 - - ...
-2
votes
1answer
24 views

finding a string among several zipped files (webapps)

We have to find a string, let's say "foobar" among several webapps. However, some webapps contain zipped files, eg log4j.jar. Therefore, grep -IR "foobar" /pathto/tomcatroot/ won't work, because of ...
1
vote
3answers
374 views

Grep last match from file

I'm running the following command against a log file and only wanting to get the last/latest match. Sometimes there may only be one match, other times there may be multiple, which is causing an issue ...
0
votes
1answer
129 views

grep multiple occurrences with intervening lines

I'd like to do the following: Given a file with many lines, several of which match a pattern, output the first matching line, the last matching line, and all the lines in between (I want them in ...
1
vote
1answer
360 views

Grep --only-match without new line

I want to use grep command to extract some strings from my data file. data file format a=1,b=2,c=3, a=4,b=5,c=6, I want the out format a=1,c=3, a=4,c=6, I tried the below command grep -Po 'a=.*?...
6
votes
5answers
3k views

Calculate sum of several sizes of files in Bash

I have list of files in a file, cache_temp. In file cache_temp: /home/maildir/mydomain.com/een/new/1491397868.M395935P76076.nm1.mydomain.com,S=1740,W=1777 /home/maildir/mydomain.com/een/new/...
1
vote
1answer
331 views

grep does not work in particular folder on centos?

It's a bit strange with the grep command. When I am in the mail folder, it always produces help text. At first, I thought I had wrong synxtax but it is working on its parent folder. What could be the ...
4
votes
2answers
368 views

How to show specific luns from lsscsi command?

I need to grep specific luns from the lsscsi command. For example: [root@e15l1 ~]# lsscsi 4 0 1 | awk '{print $1,$6}' | head [4:0:1:0] - [4:0:1:1] /dev/sdab [4:0:1:2] /dev/sdj [4:0:1:3] /dev/sdz [4:...
3
votes
2answers
2k views

Ansible yum update then email me the results

Writing a playbook to perform yum updates and then get an email from each server. I'd like the email to contain the changed contents of yum.log. IOW, I want the results of: grep [today's date] /var/...
0
votes
1answer
240 views

Grepping a single line from iftop

iftop -t -L1 -s1 Output: iftop -t -L1 -s1 | grep "Total send and receive rate:" Output: How can I grep just the "Total send and receive state:" line?
0
votes
1answer
255 views

Argument list too long with grep

Normally to search and replace a string in a selection of files, I would find with: grep -rl 'pattern' . This works fine unless you have a LOT of matches. Anyway, I was looking around and found a ...
1
vote
0answers
151 views

Legal Discovery - how to search .eml files for keywords and copy the results to another folder on macOS/Unix?

I've got a Kerio Connect mail server that saves all of it's emails in a relatively standard mail spool folder structure as raw .eml files. I've been tasked with performing a keyword search against ...
0
votes
1answer
533 views

Trying to do grep and sed from a file and push the output into a variable

Can we do grep and sed from a file and push the output into a variable grep "^/dev/disk/by-id/scsi-*" /tmp/disks.txt | sed '{'s/=.*//'}' Output would be like this: /dev/disk/by-id/scsi-...
-1
votes
1answer
406 views

Why grep doesn't work in the /usr/lib/systemd/system directory?

The other day I was on a RHEL7.1 system and I wanted to search for a specific word in the /usr/lib/systemd/system directory where all the systemd unit files are located. I used the grep command as ...
-1
votes
1answer
79 views

how do i remove local ip from list of ip addresses?

I have a variable that contains list of ips and i will like to remove the ip of the instance where the variable is set Please see below [root@ip-10-10-2-100 ~]# INSTANCE_IP=$(curl -s http://169.254....
-2
votes
1answer
92 views

Listing all packages, but without addional text

In this time I am working of project, what tell you, what software you have installer and what you can install. In this time I have problem with this command: grep -hn Package: /var/lib/apt/lists/* . ...
3
votes
1answer
37 views

How to signal the presence of a pattern via exit code, without altering STDOUT

I need to run cmd1. If and only if PATTERN is missing from its STDOUT, i need to run cmd2 too: cmd1 | grep "$PATTERN" || cmd2 But I'd like to see all output from cmd1, not just the lines that ...
0
votes
1answer
186 views

More elegant ps aux | grep [g]rep do not work

I am running the command: ps -ef | grep [p]ts/1 The result is: root 13820 1733 0 14:19 ? 00:00:00 sshd: root@pts/1 root 13822 13820 0 14:19 pts/1 00:00:00 -bash root 15847 ...
1
vote
0answers
291 views

Grep - Looking for non printable or higher range ascii characters

We faced an issue when someone copied a string from somewhere in one of the metadata xml files that contained ascii characters 239 (0xef), 191 (0xbf), 189 (0xbd) We fixed the problem in known file, ...
2
votes
3answers
3k views

Cron: only send mail if output contains string

Can I make cause cron to only send the email if the output (stderr) contains a certain string? I'm aware of this answer but the command I run doesn't distinguish between stdout/stderr, it always just ...
1
vote
1answer
4k views

Escaping special characters in grep regex

I am trying to run a grep regular expression on a file, where I have to exclude lines where "00" and "0" appear. I came up with this expression: grep -a -E \"stored\"\:\ \"\*123\*(?!00)[0-9]{2,5}\#\" ...
34
votes
3answers
8k views

Grep in a huge log file (>14 GB) only the last x GB?

I need to search something in a huge log-file (over 14 GB). I'm pretty sure it's in the last 4 GB or so. Is there a way to skip the first X GB to speed things up?
1
vote
0answers
54 views

Grep error or limitation reached on 1.2GB text file?

grep on large file followed by tail produces incorrect result, see proof below. The file is 1.2GB large, but grep should process it as a stream, so where could be a problem? root@condor1796 /home/...
7
votes
2answers
2k views

How to programatically add secure_path in sudoers file

I'm trying to build a user data script for an EC2 instance that builds node and npm from github, and then starts a service. To grease these wheels, I need to add: :/usr/local/bin to the end of the ...
-2
votes
1answer
87 views

How to turn this into an alias?

I frequently use this command: grep -rnw donkey | grep market | cut -c -80 How can I change it into an alias on Linux? I tried: alias search='grep -rnw $1 | grep $2 | cut -c -200' But when I run ...
5
votes
1answer
3k views

Grep Not Working (on some files)?

I have a MSSQL database dump I'm trying to grep through. However, grep does not seem to work on it, at all. Here is a snippet of the file. ... ALTER DATABASE [Documents] SET RECURSIVE_TRIGGERS ...
-5
votes
3answers
355 views

Search for a word before white-space

I've got a file with some e-mails: info@example.com info51351@hotmail.com test@hello.com test6261@gmail.com example@example.com example64262@gmail.com And now... I need to find a way to search for ...
3
votes
3answers
559 views

Grep regex Stdout to telnet

I'm trying to use grep to get a regex result and pipe the results on-the-fly to telnet running an open port to a node server. The grep received continuous, but varied in interval, commands from a ...
2
votes
2answers
2k views

Pipe grep result to awk with “: ” as field separator

I would like to filter the result of a grep command, eg : myRepo/path/to/my/file.php:123: error_log(' - myError'); If I do the following, it works. echo " myRepo/...
3
votes
2answers
1k views

cygwin grep running 680 times faster via ssh than via remote desktop

Running grep by opening Cygwin terminal via Microsoft Remote Desktop to Windows Server 1012 R2(same as natively?): Administrator@MYSERV /cygdrive/d/bin/beta $ time grep -inowf ...
0
votes
1answer
85 views

Can I filter output from `tail` with the `-f` flag?

I'd like to tail -f the output of access_log on RHEL 6.8 but pipe and grep that output to act as a filter. Is there such an option? That is I'd like live output from: # tail -f error_log | grep <...
0
votes
1answer
25 views

how to compare and move the matched string files in different locations

I have a two different .zip files in /tmp/1/ and /tmp/2 I want to compare these two different location files and move the matched string files into /tmp/3 /tmp/1 ArchiveFile_aaa.zip ArchiveFile_bbb....
1
vote
1answer
118 views

How to write a shell script to search from a position in file instead to start from beginning of the file again

I am trying to write a shell script to find value stored after a repetitive word in a big file with millions of lines using for loop. After the finding the repetitive word how i make script to start ...
1
vote
1answer
144 views

grep command to extract data from a file

I have a file that has this line in it: $n22(s:Tstring) = "252"; I'm trying to write a shell command to grep the file and only return 252. This is what I have so far: grep -o '$n22(s:Tstring).*...
7
votes
2answers
1k views

Cat, Grep, Redirect Output… Blank File?

I just ran cat /opt/webapplications/Word/readme.log | grep -v 'Apple' and I got the output on the cli that I was expecting, which was all the lines in readme.log that did not contain 'Apple'... ...
0
votes
2answers
2k views

How to kill/close log files that are open through lsof grep deleted?

I have a deleted a large log file from our servers. so I executed this command to validate. lsof -nP | grep '(deleted)' and this showed up. how can I permanently delete the results fo this lsof? I ...
1
vote
1answer
241 views

Search lighttpd access log

The access-log on my lighttpd server is kind of huge, apx 5GB. Now I need to extract all data from a given date, 12th of February, from the log file and if possible save to new file. Is it possible ...
0
votes
2answers
231 views

Using GREP to Find Text in Files

I'm trying to use grep to find a specific line of PHP code I know for certain is present in several files, but all I get back is an empty result. Please advise on how I need to modify my grep query: ...
2
votes
2answers
2k views

Update grep on Ubuntu through apt

Say, I currently have grep version 2.2 on my system and I would like to upgrade to version >= 2.5. Other than installing grep through source code, is there a method to update grep using Ubuntu (apt) ...
0
votes
1answer
49 views

grep the result of cdrecord or wodim

I would like to parse the result/progress of a running cdrecord -v burn process. What I tried so far was cdrecord -v dev=/dev/sr0 -data foo.iso 2>&1 | grep -E 'Track [0-9]+:.*written'. ...
-1
votes
2answers
832 views

Find all files which contain pattern in directory of tar files

I have all tar files in a directory. I want to find some files in tar files without extract all tar files. I know how to work with one tar file: tar tvf abc.tar | grep xyz I want to find in all tar ...
-2
votes
1answer
297 views

Grep is not working without having read permissions [closed]

I am in a folder where I do not have read permission in contents. ls -l List all files sucessfully. I want to count files that have some attributes in their name with: ls -l | grep file????.tar.gz ...
0
votes
1answer
532 views

delete a line if it contain a particular match from a file in bash

I have a file contain lines like the following. 10 TEST NO SOMETHING 20 TEST YES SOMETHING 101 TEST YES SOMETHING 100 TEST NO SOMETHING How can I delete only the line that has ...