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

From a string, formatted as a table with spaces, how to grep all values that are equal for all columns?

The question comes from the issue: https://github.com/kubernetes/kubectl/issues/717 Kubectl returns information in a table like this: $ kubectl get replicasets -n kube-system NAMESPACE NAME DESIRED CURRENT READY …
kivagant
  • 123
  • 1
  • 1
  • 6
2
votes
1 answer

Grep date with regex

I have files with lines in the following formats: . . . 12/16/09 17:56:30.211 rest of line... . . . 12/17/09 05:34:10.809 rest of line... . . How do I grep the lines out of this file that are between two dates, i.e. all the values for one day? I…
Lance Roberts
  • 401
  • 3
  • 12
  • 29
2
votes
1 answer

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 | grep -q -m1 -F "literal string" The above command succeeds on all small files that I throw at it (small…
Jeff G
  • 121
  • 5
2
votes
2 answers

How do I make (non-gnu-)grep ignore binary files?

Hey, I am on a HP-UX server here. When recursively grepping a directory tree, I have problems when the tree also contains binary files: grep treats them as text files and displays very long lines containing a lot of non-printable characters. This…
0x89
  • 6,465
  • 3
  • 22
  • 14
2
votes
1 answer

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 match PATTERN. I know I could do something like…
Nils Toedtmann
  • 3,342
  • 5
  • 26
  • 36
2
votes
2 answers

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/path/to/my/file.php:123: …
Bastien974
  • 1,896
  • 12
  • 44
  • 62
2
votes
2 answers

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) package manager?
krisharav
  • 131
  • 1
  • 5
2
votes
3 answers

word wrap in ssh session not working with grep

When I ssh to my Linux servers and use grep like this: grep 'timeout exceeded' logfile | less word wrap does not work. However, if I use the same command but use less first, like this: less logfile | grep 'timeout exceeded' the lines wrap. I am…
user53029
  • 629
  • 3
  • 14
  • 36
2
votes
2 answers

Tail, grep and count the instances found in one command?

I am tailing a files output and grepping for lines with certain data. I don't want to output the data to the screen but instead count the number of instances it found and send that to the screen. The number of instances can be scrolling and…
user53029
  • 629
  • 3
  • 14
  • 36
2
votes
1 answer

How i can dump raw packets from an existing tcp socket using tcpdump on Mac and Linux?

Once I know the IP address and port number combo, I can run this to see some of the packets: tcpdump | grep [IPADDRESS] Anybody know how I can now see the raw packets too? Thanks!
Tomachi
  • 141
  • 1
  • 1
  • 7
2
votes
2 answers

Script to email if grep result is null

its been a long time and I cant seem to remember how to do this. I am trying to grep a logfile for a word or words and email if it does not exist in the last fifteen minutes ( I will be setting a cron job every fifteen minutes unless there is a…
Brian
  • 21
  • 2
2
votes
3 answers

Get results from grep in the order they appear?

I'm trying to grep a log file to only show lines that match a certain session ID. Thus far, it works great. However, when I get the results of my grep command, I'm not getting the entries in the order they appear. If the log file in the directory…
IVR Avenger
  • 325
  • 1
  • 5
  • 16
2
votes
2 answers

How to grep directly to ftp?

What is wrong with this syntax? How to write output directly on remote ftp because lack of space on HDD? This command is working but there is no HDD space to get the full result: find /somedir/ -name '*.*' -exec grep -i 'some string' /dev/null {} +…
eraser
  • 21
  • 2
2
votes
3 answers

Equivalent of grep -l for filenames in zipfile

Given a set of zip files, is there an easy way to list only those zipfiles that contain files whose names match a given pattern, cf. using grep -l to list only files whose contents contain lines matching a given pattern? The best I've been able to…
David Moles
  • 444
  • 1
  • 4
  • 13
2
votes
1 answer

linebreaks between results in grep

I need to occasionally monitor a spider that I have running on my server. I'm testing it to see how many iterations of it are running concurrently and to see if any of them are hanging. I use this: echo `ps -ewwo args | grep '^[^ ]*curl'` and the…
TecBrat
  • 183
  • 12