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

learn more… | top users | synonyms

3
votes
3answers
311 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
50 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
21 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 ...
5
votes
2answers
4k views

Why pidof and pgrep are behaving differently?

I have a init script in /etc/init.d/myservice for initialize a service like this: ... start() { ... daemon /usr/sbin/myservice ... } stop() { ... pgrep myservice pidof myservice ps -ef ...
0
votes
0answers
38 views

Matching number using grep [on hold]

I have this text: yuiopao:##yuiopao:14975:Alex Vart student:/home/stud/yuiopao:/bin/bash polkovar:##polkovar:5004:John Adi student:/home/stud/polkovar:/bin/bash gfgfdgd:##gfgfdgd:11000:Alan ...
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
44 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
26 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 ...
1
vote
2answers
34 views

How to get numbers of specified (range of) length from string with grep?

Here I have a bash "one-liner": cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 16 | grep '[0-9]', which generate 16 lines of 16 character alphanumeric strings. Example of output: ...
0
votes
2answers
59 views

Using regular expression to extract content of file [on hold]

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 ...
4
votes
1answer
75 views

How Do I Remove Duplicate Words With Suffixes?

How do I compare a list of unsorted words of variable length and remove duplicate words that have a suffix? Example word list: iron curl curled railroad curler ...
0
votes
1answer
51 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 ...
8
votes
6answers
12k 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 ...
34
votes
9answers
9k 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
386 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: ...
-1
votes
0answers
19 views

GREP to sort a particular error log from server log [closed]

I want to sort particular error log from server logs. I want to see when did it last happen , and how many times a day it happened. Thank you.
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
303 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 ...
-1
votes
0answers
36 views

Grep: Multi Line Search with AND clause [duplicate]

How does one use Grep to search for Multiple lines with the AND Clause. [How has this been flagged as a Duplication, Every person who linked me to another post and reported it as a Duplication, did ...
7
votes
6answers
3k 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 ...
3
votes
2answers
1k views

How to count occurrences of all the words in all the files of a directory using grep? But with count incremented only once per word per file

I have already asked a similar question but people misunderstood what i was asking. I was asking how to generate a list of every word with a word count incremented only once per word per file. For ...
8
votes
4answers
9k 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
43 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
18 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 ...
-2
votes
2answers
44 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
60 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
62 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
44 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
27 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
56 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
64 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: ...
2
votes
2answers
53 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
28 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
50 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
31 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 ...
84
votes
5answers
69k 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 ...
0
votes
0answers
59 views

Does grep “-n” option change the number of the lines depending on the regex search? [closed]

I've been working with grep on cygwin and I need the line number of a pattern; so if I write: grep -P -a -nh -i -- "ELEVATION|(\d+(\s+)?(FEET|FEETS|FT|METER|METERS))" * one of the outputs is this: ...
38
votes
8answers
52k 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
62 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
152 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
36 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
0answers
20 views

How to verify that category contains the correct file types; and if a category cotains all the correct file in the loaded file catalog [duplicate]

the first pic is screen shot of what I wrote the second screen shot is what my professor wrote he said we can't copy his work. is there any other way to write the second script code. ( easy way ...
3
votes
3answers
244 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 ...
-2
votes
0answers
22 views

How do you verify that category contains the correct file types

First script I wrote mkdir ./content/documents cp ./catalog/*.doc ./content/documents cp ./catalog/*.htm* ./content/documents cp ./catalog/*.pdf ./content/documents cp ...
1
vote
2answers
62 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 ...
6
votes
2answers
6k 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 ...
1
vote
1answer
17 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
38 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
140 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 ...