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

learn more… | top users | synonyms

20
votes
4answers
52k views

Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can ...
2
votes
3answers
100 views

How to search for text within compressed files and get just the files name

I'm trying to find just the files' names which contain an specific string. The files are compressed (.gz). I don't have zgrep installed and can't install it. Therefore I can't use the -l option. ...
0
votes
2answers
196 views

What's wrong with this grep?

> output2.txt cd # some directory i'm trying to search find views/shared -type f -name "*.js" -print0 | while IFS= read -r -d $'\0' line; do echo -n "${line%.js}" | tee -a ...
1
vote
1answer
40 views

Why does this command not sort based on the uniq count?

I have lines in a log similar to: 2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED. (10.10.10.11:61618) is not a trusted source. 2015/11/02-07:55:40.515 INFO failed with ...
1
vote
0answers
54 views

Chaining grep commands [duplicate]

I'd like to find all xml files containing 'foo', but not containing 'bar'. The command I've put together looks like this: find -iname "*.xml" -print0 | xargs -0 grep -FlisZ "foo" | xargs -0 grep ...
1
vote
1answer
47 views

Comapring columns in 2 files and printing the values that differ

I have a file (file-1) that looks like this, DIP-10097N|refseq:NP_416170|uniprotkb:P30015 DIP-10117N|refseq:NP_414973|uniprotkb:P08177 DIP-10168N|refseq:NP_418766|uniprotkb:P15005 ...
1
vote
4answers
95 views

Grep for a number in line

Can someone help me to get the below two outputs? Input /usr/IBM/WebSphere/7.0/UpdateInstaller/java/jre/bin/java -Declipse.security -Dwas.status.socket=48101 ...
1
vote
1answer
63 views

Extract characters from a serial port

I have a dummy question for you, I am trying to extract some lines from a file beginning by a special string of characters and to copy them into a file. I tried : cat /dev/ttyACM0 | grep "something" ...
1
vote
1answer
49 views

I can't get grep with regular expressions to work correctly

ssh1% cat temp sarah saab marrrrrrrrra marrrrrrrtha ssh1% grep ar*a temp grep: No match. Shouldn't this be the output? sarah saab marrrrrra I tried using putty and nxclient for Windows 10.
0
votes
0answers
32 views

Quoting the pattern in grep and it's still interpreted as an expression?

I have a simple script that I'm using to find CSS definitions in a vanilla bootstrap.css file, then I'm trying to find overridden/duplicate definitions in several other css files where other ...
1
vote
1answer
64 views

How to grep several files using part of filename as a pattern?

I have a folder which includes several files named order[ID].log where [ID] is a string e.g. orderID1.log orderID2.log orderID3.log orderID4.log ... I need to write a script in Linux to grep each ...
2
votes
2answers
1k views

list of selectable units for journalctl

In a CentOS 7 server, I want to get the list of selectable units for which journalctl can produce logs. How can I change the following code to accomplish this? journalctl --output=json-pretty | ...
2
votes
3answers
20k views

How to tell grep to match special character at beginning of each word [duplicate]

I have certain questions regarding grep. Why does the following command match '<Hello'? $ grep -E "\<H" test Hello World <Hello H<ello What needs to be done to match '<Hello' only? ...
6
votes
2answers
1k views

Grep multiple pattern negative match

So I have a bunch of Apache logs with using the standard log format. I want to get all the log lines that did not come from a web crawler. So lets say I have a file robot_patterns with entries like ...
0
votes
1answer
89 views

Grep -v filter not working

I want to filter grep results by using grep -v option. But the output does not differ when using a particular pattern. contents of log.log: ERROR error EXCEPTION exception ...
3
votes
3answers
764 views

comparing the first column of two files and printing the entire row of the second file if the first columns match

I have two files in these formats: file1 : air smell hand dude road cat file 2: air,4,21,01,13,3,2 smell,21,4,2,5,6 dude,1,31,42,1 road,1,4,2,1,4 cat,1,5,6,3,1 hand,1,4,2,1,6 mouse,1,3,5,6,2 ...
0
votes
2answers
61 views

Read a file and comment a line matching a string via shell script

Read a file and comment a line with matching a string via shell script I want to comment a matching line of file (final_ip) via shell script I have a input file (input_ip) if the searching ip is ...
2
votes
1answer
56 views

grep and septate output into two coloums

I have the following output that I have a grep'ed for ltm pool www.cloud.com-Pool-80 monitor http ltm pool www.cloud.com-Pool-443 monitor https ltm pool www.cloud.com-Pool-8080 monitor tcp But ...
2
votes
1answer
24 views

Compare two files and matched line send to new file

I have two files file1.txt a|1|cd a|2|cd a|4|cd file2.txt a|0001|hj|df a|0002|ed|nb a|0003|vf|za a|0004|er|ns a|0005|oi|lk I need a create new file with the lines matched by de second column of ...
0
votes
3answers
73 views

how to export all numbers that are unique in a few text files into another file?

I have a.txt,b.txt,c.txt. Each has different numbers as below: a.txt: 12 14 111 1 15 2 b.txt 12 18 22 23 1 2 c.txt 12 14 15 16 17 1200 The output should contain all the numbers from ...
0
votes
1answer
48 views

How to tail -f against a file which is rolled every 500MB / daily?

I would like to do the following to monitor for a pattern in a log file: tail -f ./app.log | grep "My Pattern: .*" >> ./MyPattern.txt & This is working fine until the app.log reaches ...
0
votes
2answers
43 views

Combine rows from different files, if pattern is matched

Input: two tab-delimited files, File1 and File2. File2 ($2) has to be parsed by patterns found in File1 ($1). Expected output: tab-delimited file, File3. File3 has to contain the same rows as File2, ...
0
votes
3answers
44 views

Search for number in text [closed]

I have a text file and I want so scan this text file for a specific number. Lets say the text file is: asdg32dasdgdsa dsagdssa11 adad 12345 dsaga Now I want to search for a number with the length ...
0
votes
2answers
40 views

Find a file that doesn't include specific characters

I want to find a specific file that doesn't start with a,k,G or Q and in which the third letter in the name is not a digit. I have tried many links, but found nothing regarding to this composite ...
1
vote
2answers
90 views

“egrep: empty (sub)expression” when attempting to filter out words from a list

I'm trying to follow this question/answer from Server Fault: In tail -f, how do I filter out stuff that has certain keywords? The following is producing egrep: empty (sub)expression: # Respect ...
2
votes
1answer
110 views

How to invert a count returned from grep?

I'm working on a test script. I want a particular test to run when another test does not return a failure. Here's is the basic test I am using, and its assigned to a shell script variable: cpp -dM ...
1
vote
3answers
128 views

Fast field extraction with grep

The problem I have a 32M lines file with the following format token^Iname^Iurl$ where ^I is the tab escape sequence, and $ is the end-of-line. I need to get the url corresponding to not more than ...
1
vote
3answers
86 views

How do I search for certain sections of a file and then extract only relevant information within that section?

I have a text file that is a server report which has about 1000 lines of information in it. I'm trying to write a script that can search the report for only certain pieces of information I'm looking ...
0
votes
2answers
69 views

Extract all lines from a file starting with some sequence and then output it to another file

I have a .csv file with contents similar to this: BIHAR,PURNIA,DAGARUA,BELGACHHI,BELGACHHI,KARBOLA TOLA,0,0,312,0,0,312,Fully Covered,NO,NO,01_04_2010,241656,312,2123,910,1811.5 ...
1
vote
1answer
107 views

How can I write a bash script that sends a graphical notification to all users' X displays?

This is a request for improvement and update (NOT a duplicate!) on these 2 questions & answers: Can I launch a graphical program on another user's desktop as root? Show a notification across ...
2
votes
1answer
107 views

How do I combine grep with multiple arguments and different output switches

I want to grep with multiple arguments where i want to show lines in the order they appear in my source file before one argument and lines after the other argument , i e combine: grep -A5 onestring ...
0
votes
2answers
41 views

Merge two lines of a file and adding number in the end of lines

I have a large text file abc.txt with the following format: BALT -6.110 130.600 4.06874414 -0.03254425 BALT -6.620 154.460 3.92286595 -0.17842244 BARM 32.740 140.680 3.94326190 -0.15802649 I need ...
1
vote
2answers
41 views

Extract keyword from line

I need to extract similar patterns from data below. The pattern starts with '.' or '' then to the keyword I want, then followed by ''. We can assume the format is LSUFE-numbers_ PCRF-numbers_ ...
-3
votes
4answers
158 views

bash: ls -l with grep

I have this: find . -type f -exec file {} + | grep ASCII This is the output: I want to know if is possible to show the size of the files and their path, for all files that file indicates as ...
2
votes
3answers
332 views

Shellscript to remove particular tags in HTML file

Can anyone please guide me with writing Shell Script command for following scenario. I have an html file with all tags in a single line like this, ...
2
votes
1answer
36 views

Why grep shows different results when I use file1 as a pattern on file2 and viceversa?

When I run grep -m 1 -Fnxvf file1 file2, for some couple of files I get a different line number than running grep -m 1 -Fnxvf file2 file1 (swapped files). Why? I've reduced the files to a minimal ...
52
votes
6answers
147k views

How can i count the number of lines of file with common tools in a bash?

I am redirecting grepping-results to a file, and then use cat to show its content on the screen. I want to know how many lines of results I have in my results file and then += it to some counter. ...
0
votes
2answers
331 views

Shell Script to remove double quotes within the column value

I have a input text file with 10 columns, while processing this file, in one of the middle column, I am getting this type of data.I required column value to be as below: Input Column value: "This is ...
6
votes
1answer
123 views

Function to simplify grep with an often used log

First off, sorry if this is a painfully newbish question! I'm trying make a function that simplifies grepping a log I have to work with on a regular basis. I'd like to use extended regexp with it ...
1
vote
6answers
122 views

string manipulation without awk or sed

any help on this problem is appreciated I have a text file with the following format We can safely assume that the names are always three characters long, profession 7 characters and salary 5 ...
2
votes
3answers
141 views

How to exclude the file type in find , exec and grep?

I am trying to find out the file in which the following flag is used - TRACE_WANTED". However, I don't want the find to search this flag in .c and .h. How can I issue a command to exclude the find ...
0
votes
2answers
66 views

Replace fields in file inline

I have a file (a.txt) with the following content: Redhat master 12345678 V1A 20.0/20.0.1 Windows slave 12345678 V1B 19.0/19.0.1 I want to grep line with the word "master" and replace the 4th and ...
2
votes
2answers
84 views

Works on command line but not in shell script

I have a file formated like below: 436541,000454056,Smith,john,jsmith,j-Smith@xxx.com I want to extract out ",jsmith" and write it to another file "test.txt". So I use: grep -o ...
4
votes
3answers
857 views

How to grep lines between start and end pattern? [duplicate]

I have a file which is having following content: zdk aaa b12 cdn dke kdn Input1: aaa and cdn Output 1: aaa b12 cdn Input 2: zdk and dke Output 2: zdk aaa b12 cdn dke I could use below ...
6
votes
2answers
400 views

What does the --color=auto option for GNU grep mean?

AFAICT, neither the man page for GNU grep, nor info grep, deigns to spell out what --color=auto means. I must be one of the very few people on the planet for which the meaning of this option is not ...
1
vote
3answers
4k views

How to print only the first match with grep

I'm trying to grep username: users | grep "^\b\w*\b" -P How can I get it to only show the first match with grep?
6
votes
1answer
3k views

How to grep all lines where starting line ends with a pattern and ending line ends with another?

I want to start grepping from the lines that has CK at the end of line and stop grepping when the line has D at the end. I tried grep "$CK" "$D" file..txt, but it didn't work. Input: kkkkkkkkkkk ...
-1
votes
2answers
57 views

Find file, Edit text within files [closed]

I am trying to find a file and then edit the text within these files. This is what I have so far, but sadly I'm not that well versed. Help please? grep -rl "wrongtext" ~/Library/Calendars ...
0
votes
0answers
75 views

Unable to match multiple ip addresses using grep

I am trying to match multiple ip addresses, 100.x..x.x and 13.19.x.x here is my syntax. for item in `cat s3` do egrep -o '100\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | ...
0
votes
3answers
48 views

Grepping the output of find

I am looking for a folder, but there are a lot of Permission denied messages. I want to filter these out by grepping the output. I tried this, informed by other questions: find / -type d -name ...