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

Unable to grep sourced Files in Vim

I have files which I source in my files. I want to search them, when I am at a file which have these sources. I run unsuccessfully !bufdo grep source and !bufdo grep source % Example of .zshrc which sourced PATHs I want to grep #…
1
vote
1 answer

sed can't find a file that obviously exists

I run the following command which comments out all lines that contain the text "dlclose" grep -lIR "dlclose" . | grep -v ".svn" | xargs sed -i "s/.*dlclose.*/\/\/&/g" However, sed claims that the piped files don't exist: sed: can't read…
user50914
  • 121
  • 1
  • 3
1
vote
1 answer

Comment all lines matching some pattern

I need to comment out all lines containing "dlclose" for each file in the current directory and any sub-directories (recursively). This is my best guess so far given what I was able to find out from various guides. grep -lIR "dlclose" . | grep -v…
user50914
  • 121
  • 1
  • 3
1
vote
2 answers

UNIX tool to dump a selection of HTML?

I'm looking to monitor changes on websites and my current approach is being defeated by a rotating top banner. Is there a UNIX tool that takes a selection parameter (id attribute or XPath), reads HTML from stdin and prints to stdout the subtree…
jldugger
  • 14,342
  • 20
  • 77
  • 129
1
vote
3 answers

grep/search for multiple lines in a file

Let's say I have a file with a long nested array, that's formatted like this: array( 'key1' => array( 'val1' => 'val', 'val2' => 'val', 'val3' => 'val', ), 'key2' => array( 'val1' => 'val', 'val2' =>…
GSto
  • 391
  • 1
  • 3
  • 8
1
vote
3 answers

how to grep out a particular line from a file

How can I grep out a particular line from a file in a folder. Basically I have a folder /my/cool/folder/myfile.txt I know it has line: I am cool lkasjdfaksldfj How can I grep on that file so the line starting with I am cool .... shows on the…
Omnipresent
1
vote
1 answer

ignoring errors in find / output

how do I filter out permissions errors out of find / | grep foo output?
deadprogrammer
  • 1,691
  • 7
  • 24
  • 25
1
vote
1 answer

why "grep -v" or "tail -f" stop my program's output?

I have a server for Euro Truck Simulator 2 which is called by the following command: LD_LIBRARY_PATH='$ORIGIN/../../linux64' eurotrucks2_server When the server is running, sometimes I get these lines in console (and I'd like to hide…
roughnecks
  • 111
  • 2
1
vote
3 answers

How do I extract the matching part of a regex on Solaris

GNU's grep has the option --only-matching, which prints just the matching region of a regular expression. I'm on a Solaris 5.10 box without any GNU tools installed, and I'm trying to achieve the same thing. Example: grep -Eo "[0-9]+ ms" *.log Is…
brianegge
  • 1,064
  • 2
  • 14
  • 23
1
vote
1 answer

how to exclude folders by date with find?

This is "myfolder": tree -a 'myfolder' myfolder ├── 20220902 │   ├── filefoo │   └── filebar ├── 20221001 │   ├── filefoo │   └── filebar └── 20221015 ├── filefoo ├── filebar └── filexyz etc... my command: find $folder/$(date…
acgbox
  • 376
  • 1
  • 5
  • 21
1
vote
2 answers

repeated curl + grep on macosx occasionally giving bad results?

Running macosx 10.6.2, I am seeing some extremely weird behavior with a script which repeatedly calls curl -o (file) and then greps for a certain string within it. Occasionally grep returns 1 (not found) when I'd expected 0 (found). Here's the…
akaioi
  • 139
  • 1
  • 1
  • 2
1
vote
1 answer

how to extract values from files, compare it with a variable and send to out file

I have myfolder with this files: ls myfolder filefoo filebar filefoobar For example, the content of filefoo is: total: 379400041 cache_object://localhost/active_requests 379400041 6778 0-13955161 0-14111309 0-12250718 0-11422369…
acgbox
  • 376
  • 1
  • 5
  • 21
1
vote
1 answer

Filter the output of locate not to show the Duplicates in rsnapshot

When I use locate on my server and the result is in my rsnapshot backup then I get all those duplicates. I could use grep to filter out all rsnapshot files: locate something_in_backup | grep -v /var/cache/rsnapshot but then I would miss files in…
rubo77
  • 2,469
  • 4
  • 34
  • 66
1
vote
2 answers

Zip all files returned from "grep-ril" command

I'm using grep -ril to be able to see all files that contain a certain string: [user@machine]$ grep -ril "test string" file1.log file2.log file3.log file4.log ... I then would like to zip all of the files that have been returned by that command. Is…
Ress
  • 45
  • 1
  • 2
  • 8
1
vote
0 answers

How to do sudo grep in a bash script?

I would like to check if the given ip address is already in the config file. But /etc/ can only be accessed by root, and I'm running the a script as admin. It seems I can't just do sudo #!/bin/bash CLIENT_WG_IPV4="10.66.66.1" DOT_EXISTS=$(sudo grep…
Houman
  • 1,545
  • 4
  • 22
  • 36