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

learn more… | top users | synonyms

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 [on hold]

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
299 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
33 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
35 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
41 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
59 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
59 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
39 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
26 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
54 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
63 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
50 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
27 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
26 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
68k 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
58 views

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

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: ...
34
votes
8answers
51k 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
59 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 ...
4
votes
1answer
53 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
5answers
148 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
34 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
237 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
21 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
61 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
16 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
138 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
45 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 ...
0
votes
1answer
53 views

replace long text string (script with MANY special characters). sed, awk, grep

My site was hacked / infected. I replaced the url of the malicious link, but other elements in the malicious script are still making my site get blocked. Without inserting a hundred or so "escapes", ...
0
votes
3answers
38 views

Using grep and looking for unique occurrences [duplicate]

I have a text file of this type, and I would look for any lines containing the string Validating Classification and then obtain uniquely the reported errors. I do not know the types of possible ...
3
votes
3answers
742 views

bash - extract filenames from html file containing multiple links

I have downloaded an html file autogenerated by a script on a webpage. The file contains multiple links, including links to images I am trying to extract the full names of the images, for example ...
4
votes
3answers
258 views

Grep exact number of digits and some other characters

I'd like to parse a file containing 5 digit numbers separated by comma or dash, lines like : 12345,23456,34567-45678,12345-23456,34567 My goal is to find lines which have incorrect formatting eg. ...
1
vote
5answers
10k views

Printing a new line using awk

I have a load of files in which I need to take out specific rows and then put the data I've taken out into a spreadsheet. An example would be my file shows: Name: w Age: x Height: y Weight: z I ...
14
votes
2answers
555 views

How do I use grep while keeping the original text color? [duplicate]

For example, I have a output: Hello, this is the output. (let's say that for example hello is colored red, and the is colored green, and output is colored purple). Now, let's say that this is the ...
48
votes
9answers
26k views

What makes grep consider a file to be binary?

I have some database dumps from a Windows system on my box. They are text files. I'm using cygwin to grep through them. These appear to be plain text files; I open them with text editors such as ...
3
votes
3answers
93 views

Is it possible to use grep lookaroud multiple times?

<table name="content_analyzer" another-key="id9"> <type="global" /> </table> <table name="content_analyzer2" another-key="id12"> <type="global" /> </table> ...
6
votes
4answers
557 views

In grep command, can I change [:digit:] to [0-9]?

Will grep [0-9] work in the same way as grep [:digit:]?
0
votes
0answers
19 views

check if a variable contains letters and exit if true [duplicate]

I am using the line below to verify that an argument do not have a letter. If it have, the script will exit. Can you help me on how I can exit the script if the argument have a letter? echo $1 | ...
3
votes
3answers
43 views

Grep that works with overlapping patterns

I want to count the number of repeating patterns aa in a very big file. So I use the following command: grep -o "aa" ./bwt/dblp.txt | wc -l This works, except when I have a string such as aaa, ...