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

learn more… | top users | synonyms

2
votes
4answers
404 views

Zgrep stop after first match when arguments are passed from xargs

I'm using this command to find patterns in zip files (similar to the one) suggested here http://superuser.com/questions/144926/unix-grep-for-a-string-within-all-gzip-files-in-all-subdirectories find ...
2
votes
0answers
285 views

exit code of grep in trap where the script is launched by upstart service

recently I encountered a problem in ubuntu upstart and trap in bash shell. I use ubuntu 12.04 the upstart script(/etc/init/player.conf) is: start on (local-filesystems and runlevel [2345]) stop on ...
10
votes
2answers
865 views

Script to quickly test all keyboard keys

I need to check some notebooks for bad keyboard keys, and so I'd like to speed that up as much as possible. I found nothing for this specific task, so my idea is a script that reads the pressed keys ...
2
votes
2answers
132 views

regular expressions with grep

I have this command right here: grep -B10 -A10 '14:14:50 {"channels":["/alerts/6979/new"],"data":"New alerts for unit 6979"}' mygateway.log Rather than searching for 14:14:50 I would like the 50 to ...
3
votes
5answers
347 views

How to grep, then search and replace on the output?

I have some output from iconv, e.g. $ iconv -l | grep ISO | head -5 CSISO4UNITEDKINGDOM// CSISO10SWEDISH// CSISO11SWEDISHFORNAMES// CSISO14JISC6220RO// CSISO15ITALIAN// durrantm:~ How can I change ...
2
votes
1answer
93 views

How to grep including single quote in a file

I have this line from file.php: 'user' => '', What would be the appropriate command using grep to query the exact line?
3
votes
5answers
679 views

How can I concatenate a single column of output into a list?

I'm using: ls /proc | grep -v "^[0-9].*" to get a list of all the files and directories in /proc that don't begin with numbers. The output is a single column list, i.e.: acpi asound buddyinfo bus ...
20
votes
3answers
3k views

grep: memory exhausted

I was doing a very simple search: grep -R Milledgeville ~/Documents And after some time this error appeared: grep: memory exhausted How can I avoid this? I have 10GB of RAM on my system and few ...
1
vote
3answers
841 views

grep for an alphanumeric strings of any length with a colon on each side

How would you grep for an alphanumeric strings of 1 to 50 characters (ideally, any length would work too) with a colon on each side – a typical result would be all the lines containing the string ...
2
votes
2answers
100 views

selecting specific string in a field

I have this file: N104 F1810 N104 F3810 N104 F810 N104 F305 and a script to grep an input. Script: enter input read input cat file | grep $input when I input “810”, I get the ...
0
votes
2answers
116 views

Count lines with alphabet in linux

I have a file with a number of lines in a file filename. I want to count how many lines start with character 'a', with 'b' and so on in one go. What command i should execute.?
3
votes
2answers
361 views

grep filter all lines plus one before each hit

I want to parse some output so I exclude all lines that contain either foo or bar, as well as all lines immediately preceding those lines. For example: echo " 1 some line 2 line to exclude because ...
10
votes
5answers
1k views

Using grep or awk

To capture a particular pattern, awk and grep can be used. Why should we use one over the other. How does this work in the background? Which is faster and why? E.g If I had a log file and I wanted ...
2
votes
3answers
370 views

Command substitution in for loop not working

I want to keep all files not ending with .bat I tried for f in $(ls | egrep -v .bat); do echo $f; done and for f in $(eval ls | egrep -v .bat); do echo $f; done But both approaches yield the ...
2
votes
2answers
99 views

Filtering the result of the find command, so that it returns only directories

Is it possible to get only the results from find that are directory paths? Using find with some option, or using grep or some other utility the results are piped into as a filter? I thought something ...
2
votes
4answers
772 views

How to use the grep result in command line?

When I use grep to find some text which I need, it will display lines containing a match to the given pattern. For example, # grep -r ".*Linux" * path0/output.txt:I hope you enjoyed working on ...
0
votes
1answer
83 views

Problem with small bash script

I often run find in my code projects when I make a change somewhere and I have to find where it impacts other pieces of code, so I thought about writing a very small script to make this easier, call ...
1
vote
2answers
251 views

How can I combine grep with file and extra regex

I have a file of strings in each line. For example: AAAAA BBBBB CCCCC etc I want to check each string one by one whether it exists in a series of files in a specific directory. I ...
4
votes
4answers
2k views

How to grep for pipe |

How can I grep for line containing pipe character | or for character >: files content: |this is test where is > this is none now what I need using grep command is grep -iE "<some ...
3
votes
2answers
991 views

Optimizing a shell script with long running while loop

I have written a shell script which has to do the following: Capture session commands into one file. Every individual command into separate file. Mail every individual command file content based on ...
3
votes
1answer
357 views

Speed up zgrep on a multi-core computer

I'm running zgrep on a computer with 16 CPUs, but it only takes one CPU to run the task. Can I speed it up, perhaps utilize all 16 cores? P.S The IO is just fine, I could just copy the gzipped file ...
1
vote
3answers
415 views

Escaping * with Regular Expressions and Grep

I have a file that has unique lines that start with 2 stars (**). However when I run a grep command for grep \*\* fileName I get all of the lines in the file. This is very unusual, and what I ...
2
votes
2answers
391 views

Faster way to find matching patterns from external file grep -f {patternfile} {source} in BASH

In *nix terminal (Bash) os there any other faster way to find a pattern (or excluding them - egrep -v option) than using this: grep -f {patternfile} {source} Using this option is painfully slow for ...
2
votes
3answers
403 views

How to grep the last number on a line in a bash script

I have output from the smartctl -a command; one of the lines looks like this: 9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 301 I've placed this into a variable (if that's the correct term) ...
2
votes
2answers
562 views

Print a text file from a line number to another after searching for the lines

I want to print a text file from X line number to Y line number The value of X & Y is determined by searching for a specific line in the text file(in this case the page number) I search for the ...
1
vote
1answer
85 views

Numbering the output of grep

When we're filtering the output with grep, is there any way we can get line numbered output, like we get with cat -n? I'm not asking for the grep -n option which shows the line number of the match in ...
0
votes
1answer
175 views

Stream grep from subprogram, not tail file

Does a simple one liner exist for grepping continuous output from a program rather than just a file? Now just as an example, I would like to skip lines containing PHPUnit in them. For obvious reasons ...
4
votes
1answer
362 views

grep: display filename once, then display context with line numbers

Our source code has error codes scattered throughout. Finding them is easy with grep, but I'd like a bash function find_code that I can execute (eg. find_code ####) which will provide output along ...
2
votes
2answers
748 views

Some UTF-8 characters not being recognized by grep or sed

Trying to determine all characters in a file. The file sample consists of: a eɪ abandon əˈbændən ability əˈbɪləti able ˈeɪbəl able ˈeɪbl abortion əˈbɔrʃən abortion əˈbɔrʃn about əˈbaʊt above əˈbʌv ...
-1
votes
1answer
676 views

if condition, loop in grep [closed]

Could someone please provide help for me. I tried to start writing a shell script but am getting hung up with this issue. I need to grep commands "adb shell ps" and find in it 3 processes with names: ...
1
vote
2answers
332 views

Grep a string from file

I have 5 filenames created inside a folder for one operation.The filenames are in the following format. ES_currentdate_currenttime_processid_uniqueid.log I want to read the status from the latest ...
2
votes
3answers
4k views

How to find multiple strings in files? [duplicate]

I use the following command to find files with a given string: find /var/www/http -type f | xargs grep -iR "STRING1" But how can I find files which include "STRING1" OR "STRING2" OR "STRING3"? ...
2
votes
3answers
2k views

Grep in couple thousands files

I have directory with cca 26 000 files and I need to grep in all these files. Problem is, that I need it as fast as possible, so it's not ideal to make script where grep will take name of one file ...
4
votes
5answers
2k views

grep for multiple strings in files, and then list the files in the order of size

I am in a folder with lots of .txt file, I would like to find all the files which contain both stringA and stringB (not necessarily on the same line), then list these files in the order of the size ...
5
votes
1answer
773 views

Piping search term (not filename) to grep

I want to pick out certain lines containing a given number from a file. The file I want to search is called os_clusters/piRNA_clusters.bed. awk '{if (a[$0]++ == 0) {split($0,b,"."); ...
4
votes
2answers
165 views

Printing lines from one file if part of them appears in another. Both files are millions of lines long

I have two files, let's call them 123.txt and 789.txt. 123.txt is 2.5M lines long, and 789.txt is 65M lines long. Is there any way to use grep or similar to keep any lines from 789.txt that contain ...
3
votes
3answers
975 views

How to find first match in multiple files

Is there a way for the find command to search for the first match or occurrence of a string or pattern within each of multiple files? I've been using the usual syntax: find dir -iname '*.ext' -exec ...
1
vote
4answers
73 views

Extract data from line and prepend to the line?

Ok, I have some data in the form: <a href="/praha/jaktovidi/_zprava/jak-to-vidi-rektor-richard-hindls-5-cervna--1220102"> <a ...
1
vote
2answers
144 views

Tell a regex expression to skip the beginning of a line before matching

If I had a string like 45mb ./aaaa/bbbb/cccc/dddd and I use a regex like [^\/]*\/ it will match 45mb ./aaaa/bbbb/cccc/ I only want it to match ./aaaa/bbbb/cccc/ but I can't figure out how to do ...
1
vote
4answers
386 views

using simple regex quantifier expression in grep

Does anyone know why ls | xargs -n 1 basename | grep -E '[0-9]{1}' does not only show occurrences of a single digit between 0-9? For example if I have: touch 1 touch 22 touch 333 touch test_file ...
1
vote
1answer
57 views

How to use GNU tools to extract and merge two substrings of the same string?

Suppose I get the following result after doing a grep "emailed" /home/John/logs/2013-07-10.171222-0400EDT.html:I have emailed Mark. Thanks I want to extract the date from this so that my output ...
3
votes
2answers
204 views

How to grep recursively in order of last modified time?

grep -r does a recursive search in all files in a particular directory. However, if I want these files to be read by grep in the order of their last modified time, how do I do that?
1
vote
1answer
65 views

grep curly-bracketed entries from text file

I have a file with many curly bracketed words, ex. {test1}, {test2} - how would I grep for these words and output a distinct list of them? output example: {test1} {test2} I've tried this which ...
1
vote
3answers
147 views

Cat 2 files and avoid duplication of lines

I have the file1 with the following content {"name":"clio5", "value":"13"} {"name":"citroen_c4", "value":"23"} {"name":"citroen_c3", "value":"12"} {"name":"golf4", "value":"16"} {"name":"golf3", ...
1
vote
3answers
134 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
1
vote
1answer
1k views

Reading grep patterns from a file

I have a couple of big text files and in the file UNIQS.txt I have a list of strings to grep from another file. The code I use is grep -f UNIQS.txt EEP_VSL.uniqs.sam > UNIQ_templates.sam which ...
1
vote
1answer
134 views

Is grep part of coreutils? (If not, why?)

I have read in a few websites that grep comes with coreutils (e.g. https://wiki.archlinux.org/index.php/Core_Utilities) However, after building them, I noticed that grep is missing. I wonder if I ...
4
votes
3answers
1k views

How can I grep for this or that (2 things) in a file?

I have a file that has "then"'s and "there"'s. I can $ grep "then " x.x x and then some x and then some x and then some x and then some and I can $ grep "there " x.x If there is no blob none ...
5
votes
3answers
2k views

How to grep for text in a file and display the paragraph that has the text?

Below is the text in the file: Pseudo name=Apple Code=42B state=fault Pseudo name=Prance Code=43B state=good I need to grep for "42B" and get the output from the above text like: Pseudo ...
2
votes
1answer
77 views

grep --include acts like --exclude

I'm trying to make use of the --include option of grep, but it doesn't behave as I expect. Consider this simplified test: Setup me@de31:~/tmp$ cat file.h This is a .h file me@de31:~/tmp$ cat file.c ...