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

learn more… | top users | synonyms

1
vote
1answer
163 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

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
44 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
98 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
2k 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 | ...
3
votes
3answers
24k 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
122 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 <STATUS>ERROR</...
3
votes
3answers
2k 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 ...
1
vote
2answers
103 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
60 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
43 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
79 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
105 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
50 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
67 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
41 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
219 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 user'...
2
votes
1answer
162 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
225 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
93 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
600 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 BIHAR,PURNIA,SRINAGAR,...
1
vote
1answer
131 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
171 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
44 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
52 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
226 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
510 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, <html><head></head><body>&...
2
votes
1answer
44 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 ...
0
votes
2answers
2k 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
127 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
159 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
179 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
75 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
190 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 '\,[a-z][a-z0-9]{1,...
4
votes
3answers
4k 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
528 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
6k 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?
7
votes
1answer
4k 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
58 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 /Users/...
0
votes
0answers
157 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\} | 13\.19\.[0-9]\{1,3\}\.[0-9]\{...
0
votes
3answers
59 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
331 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 '<H[1-3]>.*</H\...
2
votes
1answer
69 views

Running grep for a string with non-rendering characters

So I have a log.txt files which I can search in Notepad++ on Windows, however due to the sheer number of them, I'd like to be able to run grep on them. However, the data is formatted with non-...
1
vote
1answer
19 views

getting the root device?

I am trying to grep lsblk: lsblk | grep '/' The only issue is it returns me this: └─sdb1 8:17 1 7.3G 0 part / └─sdc1 8:33 1 7.6G 0 part /media Which is great except I only ...
3
votes
4answers
97 views

Find lines in (multiple) files that contain the given line in an input file

If I have a number of files like the following: file1: 123 456 789 012 file2: line1 922 line2 392 line3 456 line5 291 line6 201 ... file3: line1 111 line2 123 line3 19 line5 542 line6 ...
1
vote
3answers
182 views

using grep and wc commands to solve a problem

I am trying to figure out how to count the number of lines in file.txt that have at least ONE number or digit. So far I figure will count the amount of lines: wc -l filename.txt I then figure this ...
0
votes
1answer
458 views

How to use grep when file does not contain the string

In my bash script I'm trying to print a line if a certain string does not exist in a file. if grep -q "$user2" /etc/passwd; then echo "User does exist!!" This is how I wrote it if I wanted the ...
-1
votes
4answers
205 views

How to grep AND pattern with pipe

I wrote a piece of script similar to something below: srvc_location=`ps -ef| grep '${sandbox}.*pset' | head 1 | awk {print $9}` echo "SERVICE LOC : "$srvc_location But strangely this $srvc_location ...
1
vote
2answers
31 views

How can I open the file with the most matches for a given regex?

Let's say I have a directory ~/mydir that has a whole bunch of text files in it. I want to search for searchterm in this directory and then view the file that has the most matches. How can I do this ...