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

learn more… | top users | synonyms

0
votes
1answer
38 views

how to interpret “grep -Rl jdk1.7.0_80 . | xargs sed -i s,jdk17.0_80,weblogic”?

I have just installed Oracle weblogic on rhel server. Installation went successfully however the install guide given to me to run below command without explanation. I would like to know what I am ...
8
votes
5answers
43k views

Find the exact string with grep

by way of example, I've a big text file with many email address, using bash I need search/verify that an email exists (or no). Should be use (only) the "anchors"? grep '^user1@example.com' text_file ...
4
votes
3answers
203 views

grep : '+' special character

I did some simple tests with grep '+' and '*' special character $ echo 'where wh+'> /tmp/toto $ grep 'wh[e]\*' /tmp/toto $ grep 'wh[e]*' /tmp/toto where wh+ $ grep 'wh[e]+' /tmp/toto $ grep 'wh+'...
0
votes
1answer
39 views

bash program to execute something when keyword seen on stdin

Suppose I have an executable which connects to an external machine and outputs a bunch of stuff to stdout over many minutes. At the end of that output there'll be a keyword such as "STOP", or the EOF ...
5
votes
1answer
215 views

Grep word boundaries

Accorging to GNU documentation: ‘\<’ Match the empty string at the beginning of word. ‘\>’ Match the empty string at the end of word. My /etc/fstab looks like this: /dev/sdb1 /media/...
0
votes
1answer
25 views

How to display only .txt files with the name ScheduledJobs in them

I have tried this: find ~/ops_scripts -type f -maxdepth 1 -name "ScheduledJobs*" but I'm not sure how to get only .txt files to display.
2
votes
2answers
552 views

How can I grep a certain text and display its line and the line after as well

I have a file similar to: abcdef 123 ghiflk 234 sfhskdhf 483 I would like to search for a string, and the output should include the next (and/or previous) line as well. So for example: grep "bcd" ...
9
votes
4answers
11k views

Output to stdout and at the same time grep into a file

I have a script that outputs text to stdout. I want to see all this output in my terminal, and at the same time I want to filter some lines and save them in a file. Example: $ myscript Line A Line B ...
3
votes
3answers
384 views

With find -exec grep, how to print only basename or split filename/line content on separate lines?

I'm looking at source files. For PureBasic actually, but whatever the language, there are common elements involved. In my case, the command would be cover extensions pb, pbi, pbf, and pbp: find . -...
1
vote
2answers
72 views

How can I find an address in a large file with grep?

I've got an exercise to do in which I have been given a fictional email record in which the owner of the email got invited to a certain place for vacation. The log is large though, so to speed things ...
-1
votes
2answers
33 views

find common patterns btween two files

i have two files, file1 have a column with ~600 row and file2 have ~20 columns and ~3000 row. i want to find patterns form file1 that are common in file2. file1: K00001 K00002 K00003 K00006 K00013 ...
0
votes
0answers
19 views

grep, assigning colour per string match? [duplicate]

Is it possible to set the colour of a Grep result per search. I have searched and cannot find a definitive answer Am scanning through some large Error Logs and ideally looking for the output of ...
0
votes
2answers
45 views

return first instance of characters from a list

Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n ...
0
votes
0answers
42 views

Fixing Signal 13 Error on find

I have a situation where I'm trying to install softwares into my system. I'm using a fakeroot approach to install them in a separate directory where I'm listing all the files, directories and links ...
0
votes
2answers
75 views

Using regular expression to extract content of file [closed]

I have a link and I would like to return only content between www. and .com e.g www.blablabla.com would return only blablabla How could I do that? When I use grep '\.[a-zA-Z0-9\.-]*\.' it gives me ....
0
votes
1answer
58 views

grep with piping and showing multiple lines

I am trying to use grep to search a large text file, and return the paragraph containing a few key words. I also want to return the surrounding lines in the result. So, for example I have the ...
10
votes
6answers
13k 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 name=...
35
votes
9answers
10k views

Is there a way to modify a file in-place?

I have a fairly large file (35Gb), and I would like to filter this file in situ (i.e. I don't have enough disk space for another file), specifically I want to grep and ignore some patterns — is there ...
2
votes
3answers
391 views

How to count the number of words and print the lines that match exactly a given pattern?

I want to count the number of words and print the matched pattern lines which matches exactly with following pattern: abc-ERROR: The input File contains: # abc-ERROR: xyxxkkfgfr # def-Error: ...
7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
3
votes
7answers
336 views

grep with continuation lines

How can I grep/awk/sed a file looking for some pattern, and print the entire line (including continuation lines if the matched line ends with \? File foo.txt contains: something whatever thisXXX ...
7
votes
6answers
4k views

How to grep-inverse-match and exclude “before” and “after” lines

Consider a text file with the following entries: aaa bbb ccc ddd eee fff ggg hhh iii Given a pattern (e.g. fff), I would like to grep the file above to get in the output: all_lines except (...
10
votes
4answers
10k views

Why doesn't grep using pipe work here?

I have the following command: find / -name libGL.so.1 Which returns lots of lines with "Permission denied". I want to exclude such lines, so I added the following: find / -name libGL.so.1 | grep -...
1
vote
3answers
51 views

Elegant way of counting how many times patterns from a file occur in another file

Imagine that we have two for example files. The first file is filled with unique names of employees created by combining the first two characters of the first name and the last 2 characters of the ...
0
votes
0answers
19 views

redirect all errors of my script into errors.txt [duplicate]

I need to redirect all errors into other file which called errors.txt. This is my script shell : data_in=$1 fichier=$2 cd $data_in #Purge des fichiers rm -f Split/INIT_ENC.dat rm -f Split/...
-2
votes
2answers
94 views

linux on aix dont work pgrep -lf ora_pmon

pgrep -lf ora_pmon ksh: pgrep: not found. somebody know who to change the code without pgrep this is the result on another Os pgrep -lf ora_pmon 4104 ora_pmon_dbpicsr 5092 ora_pmon_dbpiss2r 14393 ...
0
votes
1answer
69 views

grep with variable in a variable

I want to filter the svlog file by date and split the result by the space, so when i enter the date, it didn't work for me, please refer to the script that I wrote below, the problem was in this ...
3
votes
4answers
83 views

Find matches on adjacent lines

I want to find adjacent matching lines, e.g., if the pattern matches are $ grep -n pattern file1 file2 file3 file1:10: ... file2:100: ... file2:1000: ... file2:1001: ... file3:1: ... file3:123: ... ...
0
votes
2answers
52 views

List Most Recent File per Sub-Folder

I have a File structure of : FOLDER/SUB_FOLDER/Text_File I have over 1k+ FOLDER and each FOLDER has at least 2 different SUB_FOLDER with each SUB_FOLDER their own Text_File. I'm trying to ...
0
votes
1answer
34 views

How do I match beginning/end of string in regex?

I know that there's ^ and $ but those are for the beginning and end of line, I am trying to match the beginning and end of string/word. I tried to use \b, which didn't work. For example: echo "lol ...
1
vote
2answers
65 views

Use of \$ at end of variable name passed to grep

I was going through one of the shell scripts and found a line: ls $dir | grep -c "$NAME.${var}\$" I understand that $ would expand the variables NAME and var, but is it required to put \$ at the ...
0
votes
4answers
83 views

grep all strings that start with a certain char, and finish with another char

I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as: [44060]apal223reaea[...
2
votes
2answers
89 views

Does the cat command pass back a file or the contents of the file?

Compare the following commands: cat f.txt | grep "someText" grep "someText" f.txt They both seem to work. But the documentation for cat says cat outputs the contents of the file rather than the ...
1
vote
1answer
35 views

How to output multiple lines using a single condition?

I have a file with the pattern: n0 n1 n2 ... ni ------------------------------- N0 N1 <empty line> if N0 is less than a specific number, I want: 2 lines above the N1's line N1's line Empty ...
1
vote
2answers
80 views

Grep command using contents of a heredoc

I'm creating a script to update a remote computer and I want to know if any user is using the computer before I update. I have a list of users and I created a heredoc with all of them. The command I'm ...
2
votes
1answer
45 views

grep a range of unix timestamps from a logfile

I have a logfile where every log event has a unix timestamp: 1460332800 event a 1460332999 event b 1460342800 event c 1460417039 event d Is there a clever unix-style way to grep all log events ...
101
votes
5answers
78k views

Can grep output only specified groupings that match?

Say I have a file: # file: 'test.txt' foobar bash 1 bash foobar happy foobar I only want to know what words appear after "foobar", so I can use this regex: "foobar \(\w\+\)" The parenthesis ...
43
votes
6answers
68k views

How do I grep recursively through .gz files?

I am using a script to regularly download my gmail messages that compresses the raw .eml into .gz files. The script creates a folder for each day, and then compresses every message into its own file. ...
3
votes
3answers
122 views

Using grep/sort/find to extract unique values

I have a bunch of text files that are named in YYYYMMDD.Txt format (so today would be 20160420.Txt). Each file is basically a log that contains a timestamp and and a unique ID, each value is ...
0
votes
5answers
172 views

How to include everything before Colon in Sed/Grep/…?

Code sed -n 's/.*tex:/[preventColonFromResult]/p' ./BitTorrentSync/Gyn/1.12.2015.tex: Agents in young <40yr? where input is ./BitTorrentSync/Gyn/1.12.2015.tex: Agents in young <40yr?. ...
1
vote
1answer
39 views

How to add an word for a line where transpose has done

I have a file fruits: apple grapes banana orange By using cat < fruits | tr "\n" "," It will give output as apple,grapes,banana,orange, Here I want to print the file name also along with ...
3
votes
3answers
374 views

Using grep with a pattern that contains a variable to be expanded

I have a file on the form 2e95d7582c53583fa8afb54e0fe7a2597c92cbba 1461065389 52880 temp/hello/file.txt 46c897a7aa8a641f46080b3431860bd0cd4a8f05 1461066221 207 temp/Another file.txt ...
1
vote
2answers
71 views

How to use a greped url provided by tshark inside a bash script?

I'm trying to use a url piped from tshark into a while loop. while read line ; do echo "$line" ffmpeg -i "$line" -c copy "filename" done < <(tshark -i tun0 -B 50 -P -V -q -l -Y 'http matches "(...
9
votes
2answers
7k views

Limit grep context to N characters on line

I have to grep through some JSON files in which the line lengths exceed a few thousand characters. How can I limit grep to display context up to N characters to the left and right of the match? Any ...
2
votes
1answer
34 views

limit grep context to a part of the result line [duplicate]

I have a big sql dump with long lines and I would like to use grep to find a certain text string. grep text_string filename.sql returns the result lines which are huge and difficult to see where my ...
1
vote
2answers
49 views

How to extract a function from file? [closed]

I am looking for a command to extract a C function from my code. It would be something like: $ grep -func "MyFunction" foo.c int MyFunction(int i) { return i+1; } I know we can extract it with ...
4
votes
4answers
1k views

Delete the matching line and several more from a file

I have a text file called file_a.txt. My first command is grep -A 12 ".production =" file_a.txt The output is a few block. Each block of string contains 13 rows I specifically want to delete all ...
0
votes
3answers
161 views

How to add a column if line contains string?

If I have a tab-delimited file containing the following lines: Sample1-Baboon 1 2 3 4 Sample2-Human 1 2 3 4 Sample3-Human 1 2 3 4 Sample4-Baboon 1 2 3 4 How can I add a new column ...
1
vote
1answer
76 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ....
2
votes
5answers
9k views

Deleting Lines Containing a Specified String in Different Files

Suppose there are two files in web/ named foo.php and bar.php. The 1st line of foo.php is "sdajgeSTRINGdsad" and the 10th line of bar.php is "gdfhu98324STRING". The task is to first locate these two ...