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

learn more… | top users | synonyms

1
vote
1answer
111 views

Calculate max TPS from log file

I have this bash script to compute the max tps from an application's log file. The script works but it takes several hours to run on files with millions of entries. The log entries have the following ...
1
vote
3answers
419 views

How to extract XML from a text file

I have a text file as below. 1001=<?xml ns=dkfj><home><taga>dkjf</taga></home>1002=<?xml ns=dkfj><home1><taga>dkjf</taga></home1> I need ...
1
vote
1answer
35 views

display users that logged in since a date using last

I am trying to display the user name of the accounts that have logged in during the past month using the last command. At the moment I have this last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul ...
1
vote
1answer
34 views

Search for file in folder1 and execute a script if that file isn't in folder2

folder1 contains only .flv files. folder2 contains only .mp4 files. All .flv files in folder1 SHOULD have a corresponding file ending in .mp4 in folder2 : /folder1/123.flv and /folder2/123.mp4. I ...
3
votes
3answers
72 views

Filter a list of files based on file attributes

With find you can search by file attributes like -type, -executable etc. How to achieve something similar, but from an existing list of files? e.g. the output of dpkg -L <package_name>. A pipe ...
0
votes
2answers
65 views

Problems with regex in grep

I'm trying to remove malware code from a site using a script, I'm having trouble getting the regex right for the malware part. What I want to do eventually is to use sed in order to find the ...
1
vote
3answers
70 views

Find specific class name in a file [closed]

I have a Java file which has a class names as below: class HelloWorld { public static void main(String[] args) { // Prints "Hello, World" to the terminal window. System.out.println("Hello, ...
2
votes
4answers
938 views

Compare awk vs. grep

I have run below two commands for a very large files grep -E 'string1|string2' 151103*.log|grep 'string3' | grep string4 awk '/string1|string2/ && /string3/ && /string4/' 151103*.log ...
1
vote
0answers
30 views

accessing old data from syslog

I look after various MySQL DB's which we have recently moved to Linux servers (from Windows). They run fine and everything is good. However, this morning i needed to check the error logs, but these ...
0
votes
2answers
66 views

grep between two lines with specified string [duplicate]

I have this simple plat file (file.txt) a43 test1 abc cvb bnm test2 test1 def ijk xyz test2 kfo I need all lines between test1 and test2 in two forms, the firte one create two new files like ...
2
votes
3answers
480 views

Excluding multiple patterns with one grep command

I was wondering if there is a best way to run the following command cat cisco.log-20151103.log | grep -v "90.192.142.138" | grep -v "PIX" | grep -v "Intrusion" I tried cat cisco.log-20151103.log | ...
1
vote
1answer
51 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
56 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
53 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
100 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
4answers
105 views

How to get the number of each punctuation mark from a file

grep '[".?!"]' Returns the lines that have one of these but I have no clue how to tell how many are in each line, let alone how many ., ?, and ! there are.
1
vote
1answer
62 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.
1
vote
1answer
116 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
80 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
1answer
59 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 ...
0
votes
2answers
78 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 ...
0
votes
1answer
103 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 ...
2
votes
1answer
42 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
0answers
43 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 ...
0
votes
1answer
74 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
48 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
50 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 ...
1
vote
2answers
146 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
134 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
177 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 ...
0
votes
2answers
239 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 ...
2
votes
1answer
146 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
42 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
48 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_ ...
2
votes
3answers
426 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
43 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 ...
2
votes
3answers
140 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. ...
6
votes
1answer
124 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
139 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
156 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 ...
2
votes
2answers
130 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 ...
-3
votes
4answers
184 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 ...
3
votes
2answers
85 views

different results from awk and grep

This gives result 124: awk 'BEGIN {FS = ","; count = 0}; { if ($7 ~ /Nature Life/) { count++ }} END {print count}' file.csv This gives result 123: grep -cE '^([^,]*,){6}[^,]*Nature Life' ...
2
votes
2answers
38 views

Can i run grep from cPanel without SSH?

I need to search a large amount of files on my hosting that runs cPanel. They don't have SSH, is there a way I can run grep in any other way to search my files for a certain piece of text?
6
votes
2answers
478 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
137 views

Searching for occurrences of , before specific word

I have a csv file in which I have to find the number of lines with the specific word "Happy" at the 6th position ie. after 5 commas. So i am writing this: grep -P -c ",\{5,\}"'Happy' file.csv but ...
0
votes
0answers
111 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\} | ...
4
votes
3answers
2k 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 ...
0
votes
3answers
55 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 ...
4
votes
2answers
330 views

difference between [] and \(\) in Basic Regular Expression

Consider: $ echo '<H1>heading</H1>' | grep '<H\(1\|3\|2\)>.*</H\1>' $ <H1>heading</H1> and $ echo '<H1>heading</H3>' | grep ...