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

learn more… | top users | synonyms

1
vote
3answers
120 views

Grep for multiple strings, show number of lines after one of the strings (but not the other)

As the title suggests, I would like to search a file for multiple strings and for one particular string, show the 5 lines following it as well. cat file | grep -e 'string1' -e 'string2' works of ...
26
votes
6answers
26k views

How to pipe the result of a grep search into a new vi file

I'm using grep -e Peugeot -e PeuGeot carlist.txt to search through carlist.txt and pull out some items and I presumed that grep -e Peugeot -e PeuGeot carlist.txt | vi would pipe it through for me but ...
-1
votes
1answer
37 views

Get the respective tablenames if it matches particular pattern

I need to list the table names if it finds particular pattern from the below file. CREATE TABLE IMS.ACTIVITY ( "ID" INTEGER NOT NULL , OWNING_TYPE FOR COLUMN OWNIN00001 VARCHAR(20) ...
2
votes
1answer
120 views

In bash, grep for a line beginning with \, and assign the result using backticks

In bash, I'm trying to grep a file for a line beginning with a \, and return the result using backticks. For example: echo \\Hello > myFile out=`cat myFile | grep '^\\Hello'` echo $out returns ...
1
vote
3answers
228 views

how to extract a value from a string in xml using grep or awk in Linux

I have a file containing: DEVICE="7" PGMNR="24" VCONF="800" In this file, I want to find PGMNR="24" and I need the value 24 without the ". The PGMNR="24" may be located anywhere in the line. The ...
0
votes
0answers
29 views

grep names from big list and sort it according to pattern [duplicate]

I have 2 big files as shown below. I want to read the pattern file and grep the line from full-info file and sort the channel name order according to pattern. pattern file HBO COMEDY; DTV CABLE ...
1
vote
1answer
145 views

Figure out the PID of exact node.js application

Here is an output of my ps aux: ps aux | grep "node" root 2501 0.0 3.4 720400 68512 ? Sl 16:09 0:03 node /etc/skbx/host/skbx.js 8081 tula13 8082 8084 8085 10.8.0.6 root 20586 ...
6
votes
1answer
9k views

Confused about word boundary

I have been researching this a lot, but I am still not clear on it. What does word boundary mean? What does it do? So, for example, could someone explain this command to me please? egrep ...
-1
votes
2answers
60 views

passing all the contents of a file as keywords after grep command [duplicate]

Suppose I have two files named a.txt and b.txt. Is there any way to use all the contents of file a.txt to use as patterns for grep command if I want to search in file b.txt? General format of grep ...
3
votes
1answer
50 views

comparing 2 lists with additional data to be printed

I have a file lets say file1.txt ENSG00000223116 AL157931.1 ENSG00000233440 HMGA1P6 ENSG00000207157 RNY3P4 ENSG00000229483 LINC00362 ENSG00000252952 RNU6-58P I have another file say ...
3
votes
3answers
2k views

Using grep/awk/sed to sort and combine 2 files

Ok I am running into a problem. I am taking a wifi log that has MAC addresses listed in it. I want to find out what MAC vendors/manufactors for the devices that are connected to my router. I have 2 ...
1
vote
1answer
73 views

grep -E regex syntax changed?

A lot of documentation I've read says that the following command should match lines where x appears at least 3 times in a row but no more than 4 times in a row: grep -E {x}\{3,4} E.g. ...
2
votes
3answers
98 views

Count of several keywords on a site

I currently have the following command wget -O - -q http_url_goes_here | grep -Eci '(cart|shop|buy|order|store|shipping|products|price)' It gives me a count of ALL occurences of each of the ...
0
votes
1answer
59 views

grep a pattern that doesn't have dot after it

File a contains, abcd abcd. defgh defghabcd. defgh. abcd abcd .defgh How can i print all the lines that has the pattern abcd without a dot suffix? It must print, abcd defgh. abcd abcd .defgh #. ...
0
votes
1answer
102 views

Modifying the search result of grep

Normally, we can search a keyword in a list of pdf files using the following command: for file in *pdf; do pdftotext "$file" - | grep keyword done Now, from the search result, If I want to find ...
4
votes
1answer
372 views

Match pattern \\\" using grep

I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\". The much shortened string looks like, '[{"testId" : "12345", "message": "\\\"the ...
152
votes
5answers
339k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
0
votes
1answer
57 views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA ...
2
votes
1answer
103 views

Double square parenthese inside grep pattern

grep "^[[:space:]]*clientPort[^[:alpha:]]" zoo.cfg This is a grep pattern to extract the line that contains the port number from the configuration file. 1) Normally in a regex, I use square ...
-1
votes
1answer
64 views

Grep command to output in file

grep -irm 1 "some_pattern" . | wc -l > myfile.txt I used this command to find out the number of files having the given pattern. I want to output it in file. But I couldn't... what to add or ...
0
votes
2answers
48 views

Bash script to copy specific directories with pattern matching

How can I copy directories from one location to another location that matches a pattern. For example: source = /media/src/ destination = /media/dest/ The pattern is as /b/w{2}_/w{2}/b. i.e all ...
1
vote
3answers
83 views

How to search multiple search patterns from a file with grep

If I search for multiple search strings in grep : usually just do: grep "search1\|search2" somefolder/*.txt but, what if I have 100 or more search strings? Can I say like this: grep ...
8
votes
2answers
1k views

Using empty line as context “group-separator” for grep

I need grep output with context, in color, and blank lines as group separator. In this question, I learned how to define custom group-separator, and I have constructed my grep command like this: grep ...
0
votes
1answer
92 views

Need to capture part of file name into variable

I have bunch of CSV files named like so in a directory: s_m_u_supplemental_fields_account_9_4_2015_11_26_Error.csv s_m_u_supplemental_fields_account_9_4_2015_12_3_Error.csv ...
1
vote
1answer
52 views

Remove word after match

Consider the following line of text (taken from a MySQL insert): "description" varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', I want to return "description" varchar(255) NOT NULL ...
0
votes
1answer
746 views

List process by name excluding grep [duplicate]

I am trying to list all the ffmpeg processes that are currently running on Debian machine (Ubuntu 15). I use the following command: ps aux | grep 'ffmpeg' If only one ffmpeg process is running, I ...
10
votes
2answers
251 views

How to open grep(1p) manpage?

At the end of man grep, it says SEE ALSO\ POSIX Programmer's Manual Page grep(1p). I am not able to open the manpage grep(1p). How do I do that? Search net, Unix.SE and did trial and ...
0
votes
1answer
79 views

How to exclude directories from tar in this script?

Answering my own question yesterday, I wrote a bash script which archives all directories within a defined directory into their own separate archive files. I have also defined a variable for a file ...
2
votes
4answers
320 views

extract url between 2 strings in a file

I have a file in which each line is like this "372"^""^"2015-09-03 06:59:44.475"^"NEW"^"N/A"^""^0^"105592"^"https://example-url.com"^"example-domain < MEN'S ULTRA < UltraSeriesViewAll ...
2
votes
3answers
76 views

How to add “wrappers” around methods in source code based on a pattern, using sed, awk, grep and friends

How can I add wrappers to a file based on a pattern? For instance I have the following: ... find(css_policy_form_stage3).click with_ajax_wait expect(css_coverage_type_everquote).to ...
2
votes
3answers
95 views

Quickly find all files that start with a given string

I'm writing a command to find broken Cygwin symlinks. Right now, I'm using: egrep -rnw . -e "^\!<symlink>" But this isn't very efficient. I only care if the file starts with ...
0
votes
2answers
3k views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
0
votes
2answers
284 views

Find line within file matching pattern and make a substitution

I'm trying to simplify my life here but I'm stuck. I have a file containing multiple lines. Each line has a user and a number. I'd like to know a bash one-liner to search for a user and change the ...
-1
votes
2answers
144 views

How to lists all users who logged in on a specific day using grep and last

Hey I'm new to Linux and I'm using Ubuntu right now. However I need to answer this question: Write a command or sequence of commands that lists all users who logged in on a monday by using last and ...
21
votes
2answers
8k views

grep inside less?

I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event ...
1
vote
1answer
41 views

Excluding nested directories with grep

I would like to exclude a nested directory from my grep searches, such as /path/to/file. For example: jake@jake-laptop:~/test$ egrep -r --exclude-dir="path" "hello" . jake@jake-laptop:~/test$ egrep ...
2
votes
1answer
80 views

Using individual lines from grep outputs

I'm trying to grab lines from grep and sorting them into another command, the command I'm using for grepping atm is as follows (hasn't yet been chopped enough for what I will be using it, but this ...
3
votes
2answers
271 views

Using grep to print all of the matching strings not separated by a space

I'm looking through a text file of emails and trying to get a list of ones from a certain domain. I'm running: grep -oh "\w*domain.com\w*" file.txt This finds the lines, but only prints that ...
7
votes
4answers
2k views

How to grep -v and also exclude the next line after the match?

How to filter out 2 lines for each line matching the grep regex? this is my minimal test: SomeTestAAAA EndTest SomeTestABCD EndTest SomeTestDEFG EndTest SomeTestAABC EndTest SomeTestACDF EndTest ...
1
vote
1answer
37 views

Wanted to grep the BINARY.ear md5sum value inside the md5sum.txt file

I have a file called md5sum.txt which contain below f64e7c803e4fb1207b785dff19232a1e AM-BINARY.ear 1403519c6276b2e446d2c8cef3be0e5d BINARY.ear I want to grep only the md5sum value of BINARY.ear, ...
0
votes
1answer
41 views

Print concat vars inside loop

I have a code like this: cat input | while read p; do lynx -dump "www.xyz.com/p?=$p" | grep -m 1 -A 1 "Hello" | awk -F: '{print $2}' >> output done Where the content looks like this: [$p ...
0
votes
1answer
27 views

Suppress specific instances of search key in grep

This may have been asked before but I couldn't find it. I am grepping a lot of data files for "NaN" to search for errors; the problem is that if "NaN" appears once in a file, in all likelihood it will ...
1
vote
1answer
135 views

Outputting PID of Rails server(s) with ps aux | grep - breaks when put into an alias?

I'm trying to create an alias for an unwieldy command I'm using to output the PID and some other information about two rails servers I have running. When I simply run the command in terminal (over ...
1
vote
4answers
84 views

Match regular expression between delimiters

I have a file with several different lines. I'm looking for lines that contain(more or less) pattern like this: \[.*<.*>.*\] In other words, I want the lines that have <something> ...
0
votes
0answers
72 views

Sort Checkpoint Firewall log into easier output

I am trying to sort out this log: Aug 27 01:23:38 1.1.1.1/1.1.1.1/1.1.1.1 fw1-loggrabber[0000]: loc=12569|time=2015-08-27 ...
1
vote
1answer
66 views

Searching inside archives for specific files and patterns [duplicate]

Is it possible to grep inside a bunch of archives with regular expressions on both the names of the files they contain and the contents of those files? I would like to know which files in which ...
1
vote
1answer
43 views

finding directory entries that contain at least one subdirectory from a list

I have a file which contains directories and subdirectories and I need to search for lines which are subdirectories. I used the grep command to perform the action but it does not work. Can you please ...
1
vote
2answers
265 views

Stop grep after Nth files matched

I have many files I need to search for some string. I'm using grep -rl 'pattern' * to find files that contain the pattern. However, I'm only interested in file count - if string occurs in more than N ...
4
votes
2answers
821 views

grep string where next line does not contain string

I want to search all files inside a directory and its subdirectories for lines containing a certain string, but I want to exclude those results that contain a different certain string in the line ...
0
votes
1answer
330 views

SED - Find and replace with special characters (#, , % )

I'm aware that this is a really simple question, but I'm struggling to find a solution to this . I need to automatically find and replace in the /etc/aliases file the following section: # Person ...