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

learn more… | top users | synonyms

3
votes
5answers
316 views

Search files for a string and if found check if a file with paired name exists in the same directory

I have many different files with the same ending .ft1 that may or may not contain one specific word special. For the files that contain this word, I want to check whether another file with a different ...
2
votes
2answers
124 views

grep -E-f to capture matching ip-addresses in two files, and , print or echo result of each iteration, xx.xx.xx.xx found or xx.xx.xx.xx not found

Having one short list of few hundred ip addresses in file1, and want to identify if any of these ip addresses are missing from the master list, file2. Looking for an output > redirect to a file that ...
0
votes
1answer
19 views

'or' condition in grep -E

1)ovs-ofctl show br-int | grep "qvo\|tap" | awk '{print $1}' | grep -E "5.tap" The above(1) works fine, but if I include 'or' with grep -E like below command, I'm not getting any output. 2) ...
2
votes
2answers
42 views

How to escape metacharacters for egrep like metaquote from Perl?

Perl has a function called metaquote() to escape all special characters for a regular expression. Is there an equivalent technique for egrep? Example: If I am searching for the string abc.def.ghi, I ...
2
votes
1answer
63 views

Using sed / awk to change words between two patterns

I'm writting the shell script that should process through some text, I've got the text like that: read build { file1 file2 file3 } check build { file2 file3 file4 } read build { file4 file5 file6 } ...
1
vote
2answers
40 views

Help with regular expression in grep

someone can explain me why this regexp doesn't work in grep? ls -la ./ | grep -E '^d.*\<\..*\>$' In my (wrong) opinion this have to show me the line of the directory with a name that start ...
1
vote
1answer
63 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
261 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
30 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
30 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
53 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
54 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
57 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
585 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
28 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
63 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
233 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
41 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
48 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
4answers
75 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
52 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
67 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
65 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
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 ...
0
votes
2answers
62 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
91 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
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
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 ...
0
votes
1answer
50 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 ...
1
vote
2answers
93 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
113 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
131 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
74 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
108 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
42 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
340 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 ...
2
votes
3answers
103 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
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 ...
2
votes
2answers
90 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
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 ...
3
votes
2answers
81 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
34 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?