grep a Unix command-line utility which searches input passed to it for lines matching a regular expression, and prints the results.

learn more… | top users | synonyms

131
votes
11answers
270k views

Grep equivalent for Windows 7?

Is there a command prompt grep equivalent for Windows 7? That is, I want to filter out the results of a command: Bash use: ls | grep root What would it be from a Windows command prompt?
5
votes
3answers
9k views

How can I grep a hex value in a string in a binary file?

I have a binary file like this (open in Emacs hex mode): How can I grep if hex values '22081b00081f091d2733170d123f3114' exists in the file? 00000000: 2b08 1b00 1418 0825 0407 3830 271d 170d ...
0
votes
2answers
24 views

From logs, extract specific line after a grep by line number

I have a file, debug.log, from which I want to extract all the lines that immediately precede a specified pattern. Example: 1 blabla 2 blabla 3 HERE THE IMPORTANT THING 4 HERE IT MATCHES MY PATTERN ...
5
votes
4answers
11k views

How to combine wget and grep

I have a html-page url and I want to grep it. How can I do it by wget someArgs | grep keyword? My first idea was wget -q -O - url | grep keyword, but wget's output bypass grep and arise on the ...
-1
votes
0answers
25 views

monitoring websites using curl [on hold]

I am looking to monitor about 40 (Linux/Apache) urls hosted in a DMZ. I am thinking of using curl from a Linux box in the DMZ to do this and pass the data to a monitoring tool. My plan is to use a ...
2
votes
2answers
2k views

watching output of “ps aux | grep blah” in tmux will not work?

I am trying to run this - watch "ps aux | grep myShittyProcess" in a tmux session. This process myShittyProcess was also started in a tmux session. The ps aux works without watch command. But as ...
-1
votes
0answers
24 views

Tail a log file with today`s date

So i am trying to come up with a command to tail a log file with todays date. The log file gets updated everyday with the current date. As the number of lines for the log for any particular day can ...
1
vote
2answers
25 views

How do I search for substrings in Bash?

I want to find out and display the total amount of TTT substrings found in the first 2,000 lines in the file. I had been using grep until I tested it, and realized it does not identify substrings.
10
votes
3answers
39k views

How to find file with name=“php.ini” on linux using grep command

How to find file with name="php.ini" on linux using grep command ? Can anybody show me ?
0
votes
1answer
45 views

searching the string with the time in log file using shell script by passing variables

I want to search a string and subtract the time that is found from the current time. When used, the script should show the lines from that time or from the very next log time frame. I'm able to ...
0
votes
3answers
26 views

how to pass output of grep to “lsof -p”

I want to know the path of currently running ./a.out There are several MPI process, but I only need one of the PID of several ./a.out. So I first use below code to grep it ps aux|grep -P ...
2
votes
3answers
62 views

Find & replace on a folder of .txt (but only first 1-3 lines)

I have a folder of .txt files. They all look like this: Title: Title of blog post. Tags: tag1,tag2,tag3 Text on the post. Just my thoughts. > A blockqoute Written in *markdown.* Using ...
3
votes
5answers
4k views

How to remove lines from large text file using bash

I got a huge text file (log file) in my CentOS which I would like to remove top part of, probably couple of thousand lines each day. (Or probably just split into two) I have search this site and ...
5
votes
2answers
3k views

Finding and deleting lines from all files recursively

I have managed to grep the occurences of a keyword by using grep "KeyWord" . -r -n -i -I but, the occurences of the KeyWord are too large. I just want to delete all the lines containing that word. ...
0
votes
1answer
23 views

Bash script to find content of file in a directory and add value

I have a directory with a huge number of files. I want to write a bash script to - Enter that directory Find out which of them are Perl scripts (but none of them have a .pl extension) Add a line at ...
34
votes
1answer
56k views

What is the difference between grep, pgrep, egrep, fgrep?

I'd like a walk through on the differences between grep, pgrep, egrep, and fgrep and how I would use them.
0
votes
1answer
11 views

Which of the following use of anchor is correct in regex using grep?

Both of the below commands gives the same output, however which one is the correct method to use it? grep ^'\<that\>' file.txt Searches for the line which has that as the first word grep ...
0
votes
0answers
16 views

About grep, what's the main difference between using option E(ERE) and P(Perl)

About Grep tool in RHEL, usually I use -E option which is ERE grammar, but sometimes I use -P to use the look-ahead/behind-positive/negative grammar. I know -P is more powerful than -E, but not ...
-1
votes
0answers
13 views

Search content of odf (odt|ots|odp) documents from command line

I want to search the content of some odf document (Libre Office document) from command line. I want something like: odfgrep <search-pattern> <file-name> I found something of interest ...
3
votes
2answers
812 views

Checking if any data exists on a presumably empty storage device

So, say you've completed a full pass of: dd if=/dev/zero of=/dev/sdX bs=1M Then, you'd like to make sure the destination has been really zeroed out (ignoring the confirmation messages from dd ...
0
votes
0answers
8 views

Silver Searcher scrambles terminal when it hits binary files

When using silver searcher (ag), my terminal gets scrambled, presumably upon hitting special characters in some binaries. Of course I can just blindly type reset to get things back to normal, but ...
13
votes
3answers
24k views

How can I “grep” recursively filtering the name of the files I want with wildcards?

When I want to perform a recursive grep search in the current directory, I usually do: grep -ir "string" . But that command searches inside all kinds of files, including binary files (pictures, ...
5
votes
4answers
5k views

How can I find all files in a folder with a certain text string and an extension?

I am using OS X. I need to find files in a directory with the .php extension and the string 41 somewhere in the file's contents. I tried using grep. grep -R 41 *.php This however only seemed to ...
0
votes
3answers
55 views

What does `grep -1` do?

I'm trying to make sense of the following shell command, to get a list of packages that can be updated: dpkg --get-selections | xargs apt-cache policy {} | grep -1 Installed | sed -r 's/(:|Installed: ...
1
vote
1answer
19 views

Write file from remote server to local directory?

I want to do some grep-magic to a logfile on a remote server and write the result to a local file on my computer. Is there an easier way than my 3 step solution: do grep-magic and write file on ...
7
votes
2answers
14k views

How to grep to check if strings is not there in a file (in linux) and also the case of multiple strings?

I want to search if "ack_enabled not defined" is not there in a particular file all_defs.txt and return something, by which i can understand that the string is not there. Can anyone tell me how to do ...
-1
votes
1answer
25 views

Tail logs and use grep to exclude specific lines

I have this line that appears every minute in my log file: 2016-03-29 21:52:46,226 INFO 200 GET /api/ping (0.0.0.0) 0.34ms I want to tail this log file without showing these lines. I tried: ...
-1
votes
1answer
41 views

Moving pdf with string it and print ok or not found in every file search

I'm using the following command with pdf to search for specific strings inside several pdfs, and move for a target directory, if there is a match: pdfgrep -H "DESIRE STRING" TARGET/* | grep ...
1
vote
1answer
59 views

Find files with string

How can i grep e move pdf files that containing the string "RELAÇÃO DOS TRABALHADORES" inside? Using ubuntu 14.4. I already try to use: grep -i -Z -r -l 'RELAÇÃO DOS TRABALHADORES' . | xargs -I{} mv ...
-1
votes
1answer
46 views

Search for string inside pdf with pdfgrep and outputs only file name

I'm using pdfgrep to search for a name inside a pdf: pdfgrep -H 'Fatima Alves' RE/* This commands will output the file name and the name: RE/2011-01-RE_60822079000168_23022016_153923(1).PDF: ...
1
vote
1answer
38 views

Remove a certain part in a text file

I got the file, text.txt. In this file I have written: "test" "okay" I want to remove the " part of this file, how'd I do this?
1
vote
2answers
50 views

Counting number of occurrences of a string in all files in a folder

How do i count all the number of occurrences of a particular string in all files in a folder For example, 1.txt : 'hahaha hehe' 2.txt : 'ha hee' I would like to count the number of occurrences of ...
-1
votes
1answer
35 views

Oneliner to get the list of filenames which have last line (or line on position X) matching certain pattern?

How to get the list of filenames which have last line (or line on position X) matching certain pattern? We are looking for oneliner.
21
votes
16answers
37k views

Monitoring a file until a string is found

I am using tail -f to monitor a log file that is being actively written to. When a certain string is written to the log file, I want to quit the monitoring, and continue with the rest of my script. ...
3
votes
2answers
30 views

How to get command output of “nvidia-settings” via command line?

the case at hand: nvidia-settings -q all | grep 'Attribute.*GPUCoreTemp' gives: Attribute 'GPUCoreTemp' (system5:0.0) 58. Attribute 'GPUCoreTemp' (system5:0[gpu:0]): ...
0
votes
1answer
18 views

Separating greps output blockwise

Let's assume I have a programm that prompts a lot of information. I'm interested in only 3 messages which appear always after each other. I now want to grep these lines and separate them from the next ...
0
votes
0answers
10 views

Convert list of Hardened Linux From Scratch packages into suitable format for md5sum -c

I'd like to create a file suitable for using with md5sum -c from this document: http://www.linuxfromscratch.org/hlfs/view/development/chapter03/packages.html I imagine this should be possible by ...
0
votes
1answer
30 views

How to change file extention of every file in directory unix/linux

I have a directory of 5,000 files. All these files end with an extention of .xml I'd like to change that and have them all end with .txt How can I accomplish this in linux/mac?
21
votes
3answers
13k views

Powershell equivalent of `grep -r -l` (--files-with-matches)

In Powershell, how do I list all files in a directory (recursively) that contain text that matches a given regex? The files in question contain really long lines of incomprehensible text, so I don't ...
6
votes
9answers
15k views

How do I search for a string in a PHP file using `grep`?

I am searching for a class declaration on a site with hundreds of PHP files. How can I do this in the current folder and subfolders using grep? I tested cding to the folder and then something like ...
3
votes
4answers
22k views

Print line X lines before/after found line

I want to search for a particular string in a certain file. If I found the string, I also want to print the line X lines before (or after) that line. Can this with grep or awk, or do I need a ...
35
votes
6answers
37k views

recursive grep: exclude specific directories

I use recursive grep a lot to find source files with specific content. grep -Rni "myfunc" . On large codebases, this can get slow, so I use --incldue to restrict/whitelist extensions. grep -Rni ...
0
votes
0answers
53 views

A grep for Windows that works

I need to search a very large file (a Registry export file) for a specific string. Registry Editor has no way of simply viewing a Registry file and this file is too large to open in a text editor ...
0
votes
1answer
51 views

How can I search for text files that do NOT contain a word?

I need to be able to search a directory for all files that do not contain a certain word. My issue with my approaches so far is that they return every line of every file that does not contain the ...
0
votes
3answers
51 views

Can I grep two files against each other?

I want to grep file A for every phrase in file B, where a phrase is a string of words of length X. Ideally, it would be an approximate grep, like agrep. Is there a way to do that using command-line ...
0
votes
0answers
29 views

Finding a text string on a website and all its links

Can you help me understand process of finding a certain text string on a website and all its immediate links? I started delving into wget and curl with help of grep but was unable to come up with ...
0
votes
2answers
58 views

Using bash script to remove some lines beginning with certain characters

I have a file in the following format: --- V1 --- Hi there --- V2 --- --- V3 --- What's good --- V4 --- --- V5 --- --- V6 --- I want to use some kind of bash script to remove any of the lines ...
0
votes
1answer
46 views

Search into Windows registry with grep/cygwin

I'm trying to search and remove unrelevantregistry keys, and it sounds like Cygwin does allow access to them through /proc/registry. However, recursive grep -r (2.21) outputs error lines like : ...
1
vote
3answers
570 views

Linux command to find all instances of a file pattern?

I'm looking for a way to scan a directory recursively and print out all instances of any file that ends ".qfx". Thus, for a given directory: somedir/ fizz.qfx buzz.qfx blah/ ...
-1
votes
1answer
33 views

Syntax Error The source line is 1

I have a server list in hostlist file and I am trying to execute below script: #!/bin/bash for server in `cat hostlist`; do ssh $server 'hostname ;id $(cat /etc/passwd | grep Luyang | awk -F '[:]' ...