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

1
vote
2answers
34 views

grep a file and pipe the output to sed and store sed output in a file

Contents of source.txt: gold green white black blue yellow magenta brown tram kilo charlie tango Hi everyone! I need to solve a mystery. I'm trying to run a small script to grep a file source....
0
votes
0answers
8 views

limits for grep -A / grep -B

I have log-file which contains only 1 appearance of word 'begin' and 1 'end', and 'begin' is before 'end'. Now I want to cut this part between begin and end (including these lines): grep -A 999999 "...
0
votes
2answers
14 views

To filter out its input in lowercase character

Given an input file,I need to filter out its input in lowercase character. I tried using: cat filename | tr -s "[a-z][A-Z][0-9][:space:]" "[a-z]"
2
votes
1answer
25 views

Bash: amount of bytes used in a log file grouped by token

Assume a large log file of several GBs and several million lines where each line contains a token identifying the user account that generated the line. All tokens have the same length and can be ...
0
votes
2answers
444 views

Correctly display the GNU screen session title in status bar

in GNU screen, I want the title of the session to be displayed in the status bar. It is working but not exactly as I wanted. I have the following backtick defined in my .screenrc: backtick 100 30 30 ...
-1
votes
1answer
21 views

How to grep a multiple text line section from a beginning text pattern to an ending pattern?

For example text below , in Linux, how to get the section below from the "will be installed" to the text before "Suggested packages". Use 'apt-get autoremove' to remove it. The following extra ...
8
votes
1answer
212 views

Grep not honoring --exclude-dir

I'm having trouble searching in /var due to a hang at /var/run. I tried to exclude /var/run, but its not producing expected results: $ sudo grep -IR --exclude-dir="/var/run" '45.78.157.165' /var | ...
0
votes
1answer
20 views

need help grep playlist

I use a playlist from the Internet that gets updated every day. I want to sort and grep URLs. The playlist is a mess and looks like this #EXTINF:-1 tvg-id="ORF1.at" group-title="Deutsch" tvg-logo=...
0
votes
1answer
13 views

how to filter text file on the basis another text file.

I have two text files . One is wordlist and another one is file to be filtered. I want to remove or delete all the lines or links from the file if the line has any word from word list anywhere in ...
-1
votes
1answer
18 views

How can I filter a list of files to download those that don't already exist?

I have downloaded some files into a folder, but the download was interrupted and not all the files were downloaded. I do not want to redownload the gigabytes-worth of files I already have; I now want ...
1
vote
1answer
26 views

grep doesn't exclude directory, hangs

I'm looking for files on my server containing the text string "sometext", but I want to exclude searching in the /var/www/sometext folder (and its subfolders). So I did the following: grep -rl "...
0
votes
3answers
35 views

How to use grep to search ALL folders for text?

I'm having issues with searching through ALL the directories at once with grep. When I use the command: find . -name "*.txt" | xargs grep texthere It just takes forever and then gives me "no such ...
14
votes
7answers
11k views

Advantages of cat'ing file and piping to grep

Are there any additional advantages of cat'ing a file and piping it to grep, besides convenience? The convenience being that, when I retrieve commands such as those below from my history, the cursor ...
0
votes
1answer
16 views

Grep files for content

I am using 'find' and 'grep' cygwin commands in order to locate files based on some pattern. I am doing this: find . -iname '*.zip' -print -exec unzip -l {} \; 2> error.txt |grep -i vbs It ...
0
votes
2answers
27 views

GnuWin grep End-of-Line Anchor

I have GnuWin installed on a Windows 7 Enterprise SP1 x64 machine. I am trying to use grep 2.5.3 to match lines containing the word "true". The following is my working use-case: (echo true& ...
1
vote
1answer
24 views

Adjust grep command to avoid 'extra' lines

I have to find some text inside zipped files. I am using Cygwin. Some zipped files are empty. Obviously I don't want to have 'noisy' information about those 'empty zip files' at all. E.g. find . -...
33
votes
2answers
30k views

Grep-like functionality for Notepad++?

I would like to have some grep-like functionality in Notepad++. In it simplest version, I would like to be able to copy all lines from the current buffer that contain the word foo to a new buffer. I ...
142
votes
12answers
293k 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?
0
votes
1answer
21 views

Highlight selected words in Linux Command Usage Doc

What I want to do is print a command-help (viz. "ls --help") and grep the output for any specific word. Consider the following: ls --help | grep 'F' But what this does is just filter out the other ...
1
vote
3answers
39 views

Display file contents if it has corresponding line number

I have two files in the following format: File A 4 5 8 9 File B 1 text 2 text1 3 text2 4 text3 5 text4 6 text5 7 text6 8 text7 9 text8 What I want to have for my output is just the following (the ...
0
votes
1answer
58 views

Using grep; how do I show the Nth occurence of a pattern?

Using grep; how do I show the Nth occurence of a pattern? For instance; man sh |grep -A3 -- '-c' will return several matches. I might want to isolate the 3rd occurrence only, so that it shows: -- ...
0
votes
1answer
17 views

How do I search for “string 1” with grep only in files that contain “string 2”?

On occasion I need to search for a specific string within several files, but the results are only relevant if those files contain a second specific string, not necessarily on the same line as that ...
0
votes
2answers
20 views

Monitor log live for error. If error = rerun command and restart log monitoring, if not found = keep monitoring forever

A process in a bash script I'm developing often fails quietly (it keeps running with no error code, but it writes the error in its log file). As soon as the error appears in the log file I want the ...
1
vote
3answers
25 views

Grep by all filenames in a directory

I want to get the process status for all services running in a given directory. Right now I can check one by one ps -ef | grep ServiceName. But is there a way to ls the directory and ps every service? ...
-3
votes
2answers
25 views

I need help building a regex for a grep to show only the path to running versions of java

I need help building a grep from ps -ef to return only java paths. Say we have the following runnning process: bash> ps -ef | grep java user pid# 1 1 00:00 ? 00:04:00 /path/to/java/...
0
votes
0answers
19 views

Matching 3 or more words from fields in seperate csv files.

I have two csv files: This is csv1: 11, The Sun Still Shines in Reading, 64312, 464566 13, You and Me Together Again London, 564564, 131355 12, What's the Story Now Your Gone, 4545646, 1124545 17, ...
2
votes
3answers
38 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.
0
votes
1answer
25 views

Can I use grep to pull out a particular pattern from a file / number of files, using regex perhaps?

I have a file with a load of errors in it. I used grep to pull out all the JSONExcpetion Errors and save them in a new file like this: sudo grep -Hrn "JSONException" 2016-* >> jsonexception.txt ...
12
votes
3answers
62k views

How to grep a log file within a specific time period

I have a log file, each line in the log is prepend with a date, like so: 2012-03-06 11:34:48,657 blah blah blah... How do I grep this file and get only the lines from 8am to 11pm only? My ...
21
votes
17answers
41k 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. ...
5
votes
3answers
10k 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
56 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
12k 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 ...
2
votes
2answers
3k 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 ...
12
votes
3answers
43k 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
54 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
66 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 "Rl.*a\.out"...
2
votes
3answers
63 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 <http:...
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 ...
6
votes
2answers
4k 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
31 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 ...
35
votes
1answer
61k 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
15 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
22 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 ...
3
votes
2answers
921 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
10 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
27k 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
73 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
32 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 ...