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

learn more… | top users | synonyms

7
votes
4answers
425 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 ...
0
votes
1answer
50 views

how do I recursivley grep (or otherwise search for) hex strings

Long and short I'm trying to track down some files left by evil scum on a server. fgrep -r "STRING" /path/here has been working well for finding general stuff. However, how do I search for hex ...
1
vote
2answers
67 views

List all the html tags in a file

I want to know if there is a way to list all the html tags in a file. Lets say I have a file file.html <html> <head> <title>Test</title> </head> <body> This is a ...
0
votes
3answers
39 views

Grep display both matched and umatched lines [duplicate]

How can I use grep command to display both matched and unmatched lines? Matched line should be in red and other lines should be in normal color. Is there a grep option available to do that?
3
votes
2answers
6k views

Search string in many files on HP-UX

I need to find which files (they can have space in the filename) of a directory contains a string using only sh and system's commands (Perl is not an option). For a few files, this command works ...
3
votes
5answers
114 views

How to “grep” a string of a returned result

How to grep the number 50.0 from the string temp=50.0'C In JavaScript I can use the expression /temp=(.*?)'C/ to get it. But I cant get it running in grep.
2
votes
3answers
63 views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
1
vote
3answers
2k views

Command-line tool to search docx files

Is there a command-line tool to text-search a docx file? I tried grep, but it doesn't work with docx even though it works fine with txt and xml files. I could convert the docx to txt first, but I'd ...
0
votes
3answers
83 views

Grep finding phone numbers in files

How would I look for files in the /etc directory (but not subdirectories) that contain a standard United States long distance phone number, written using the pattern of 1-###-###-####, where each # is ...
0
votes
2answers
101 views

Solution to integer expression expected [closed]

So I when I run this code on my mac there are no errors, and it provides me the perfect output. But when I run it on Ubuntu or CentOS i get the following error integer expression expected ...
1
vote
3answers
89 views

How do I Copy and Paste lines between a start and end keyword?

I have two text files, and I want to copy a bunch of lines from one to the other. File one has a list of packages, and I want to copy it to list two. This list of packages isn't at the start of file ...
2
votes
2answers
76 views

How do you construct a grep & command to match a number of patterns depending on how many are provided at runtime?

I have exported some MS Word documents to plain text and use this function to parse the contents of the .txt files in the current directory: mo1 () { for i in *.txt; do echo "File: $i" grep ...
2
votes
3answers
82 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 ...
2
votes
1answer
64 views

How do I use grep to find a text string in files in sub folders of a parent folder without -r switch

I'm using Solaris 10 and have two grep versions one in /usr/bin and one in /usr/xpg4/bin. I have been searching for an answer on how to search for text within files within sub folders of a parent ...
5
votes
1answer
607 views

Why do I have to escape a “dot” twice?

I know that we can escape a special character like *(){}$ with \ so as to be considered literals. For example \* or \$ But in case of . I have to do it twice, like \\. otherwise it is considered ...
1
vote
2answers
34 views

Have grep output spaced for each file

When I do grep on a bunch of files, and several file have the word I am looking for, the output is hard to read as it's one after the other. Is there anyway to insert additional \n's after the ...
3
votes
1answer
82 views

Grep with spaces suddenly doesn't work

When performing a grep like: $ tail -f apilog_2014.07.09.log | grep "HELLO" | grep "99999" I get the desired output: 12:22:35 server apache2: HELLO FRIEND 99999 12:22:35 server apache2: HELLO ...
1
vote
1answer
49 views

Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?

Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas? When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
0
votes
2answers
64 views

How to count number of instance of a word starting at another word

I need to grep the MySQL-error log starting at today's date formatted like: `date +"%y%m%d"` (140710) And look for all instances of the word partitioned. I've tried various things to no avail. ...
3
votes
6answers
158 views

ls content of a directory ignoring symlinks

I have a directory in which I would like to list all the content (files and sub directories) without showing the symbolic links. I am using GNU utilities on Linux. The ls version is 8.13. Example: ...
1
vote
6answers
401 views

Print word that doesn't contain character

My file is in the following format: this!,is!,another!,test,yes! this!,is!,another!,column,yes! no,not!,another!,column My output should be: test column no It shouldn't contain the '!' ...
3
votes
1answer
29 views

annotate “include” file for grep with comments?

I do a grep sort that includes certain strings. That is, give me the lines in a file that DO contain certain strings. As in grep -fv include file > out That command looks in file and sends to ...
2
votes
2answers
103 views

tr complains of “Illegal byte sequence”

I'm brand new to UNIX and I am using Kirk McElhearn's "The Mac OS X Command Line" to teach myself some commands. I am attempting to use tr and grep so that I can search for text strings in a regular ...
5
votes
1answer
52 views

List overlapping instances of a pattern

I'm trying to capture a string and the 21 characters preceding it then output this to a new file. This is what I'm using currently: grep -o ".\{21\}gt" ../data/fastadata.txt > primerdata.txt ...
5
votes
2answers
122 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
2
votes
1answer
54 views

Using bzgrep recursively

I wanted to use bzgrep to find to text in bzip2 files. I expected bzgrep to work as grep, but on bz2 files. So I tried bzgrep -r "mypattern" . to find text in my bz2 files. Instead of the ...
3
votes
1answer
34 views

Matching several patterns on one line

I often use a program called tty0tty, which creates a null modem using PTYs. Now I want to make it part of an automated process. When I start tty0tty it prints (/dev/pts/1) <=> (/dev/pts/2) ...
8
votes
2answers
202 views

Redirecting output depending on grep regex

I am using gradle run to start a REST server. The output of the REST server looks like this: XXX.XXX.XX.XXX - <moreinfo> randomtext randomtext XXX.XXX.XX.XXX - <moreinfo> XXX.XXX.XX.XXX - ...
6
votes
5answers
235 views

Strategy to extract movies's name from this ununiform dataset?

I am working on a movie database problem to improve regular expressions, this is the problem I'm running into. My dataset looks like this: Movie Name (variable space and tabs) year Movie1(can ...
4
votes
4answers
166 views

Match two words that is on the same line

The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code: grep -oP 'FW_6.0.0, (.*)$' file Below is the output, both has the same value of FW_6.0.0 ...
4
votes
2answers
516 views

To grep 20 characters after and before match

I have the problem that I get too much information after the match for grep -RnisI --color=auto "pseudomonas" * I want to get only like 20 characters or 10 words after and before the match. What ...
2
votes
1answer
44 views

Context of the matching regular expression

I'm using egrep with the -o option in order to just get the matching part of the line, e.g. cat /usr/share/dict/words | egrep -o '(aa|ii)' Now I'd like to see some context of the match, i.e. a few ...
6
votes
3answers
190 views

Print all lines not containing punctuation

I want a regex pattern which can print all lines not containing punctuation : Input : .I am line 1 I am ! line 2 I am line (3) I am line 4 Output: ( should be) I am line 4 What I've tried so ...
1
vote
3answers
44 views

How can I find the biggest “error_log” files listed by location and size?

I host about 200 websites and I have noticed that some got huge error_log files. I would like to see which ones are consuming the most space so I can take a look on them and solve the error so they ...
4
votes
6answers
6k views

How to print all lines after a match up to the end of the file?

Input file1 is: dog 123 4335 cat 13123 23424 deer 2131 213132 bear 2313 21313 I give the match the pattern from in other file ( like dog 123 4335 from file2). I match the pattern of the line ...
1
vote
2answers
207 views

Extract Values from simple html file via grep/awk

I have another grep/awk/sed issue within the attached HTML code below. Given is a simple HTML file with table inside. The HTML is generated by a smart meter (household energy meter). Inside the html ...
5
votes
2answers
76 views

Grepping for a block of text with parts that can be optional

I have multiple entries that describes an event in a very large log file, say A.log. I would like to do two things with the event entries in the log file: Count the number of occurrences of each ...
1
vote
2answers
136 views

Using grep to get UUID

How can I get the uuid of eth0 connection out of the output of nmcli -p c using grep? Output of nmcli -p c: $ nmcli -p c ...
4
votes
1answer
194 views

Literally grep the only word in a line

I know grep -F can search for literal strings, but I want to do something like while read word; do grep -F "^$word$" FILE; done < wordlist i.e. the words need to be treated literally, at the ...
2
votes
1answer
32 views

move the search content to different directory

I am on Oracle Solaris. I am using: grep "searchstring" filename.* above command returns my search result. Now I want to move the all the files in above search result (all the files not the ...
5
votes
2answers
109 views

Why does a grep reboot the machine?

On a RHEL 6.5 Desktop, if I use: sudo grep -r foo /* my desktop reboots. Q: Why?? How to debug this? It's the third time my Desktop reboots because of this :D
0
votes
1answer
59 views

Show output only if both words match using grep [duplicate]

If packagehello does not match, the output is still displayed. Aim: to see no output in situation 2 Situation 1: user@hostname ~]$ sudo yum list 'package*' packagehello packagehello package2world ...
0
votes
3answers
32 views

Extract line number of a file which is having a non zero value before a specified string

I'm having a file which contains following data 1. verification: 10 passed 0 failed 2. verification: 10 passed 0 failed 3. verification: 10 passed 1 failed 4. verification: 10 passed 3 failed 5. ...
5
votes
3answers
175 views

cascaded grep matches color code as pattern

I am piping output of one grep comand into another grep. The first grep is using --color=always, so that the first match is colored. In practice, that means that the match is enclosed between two ...
1
vote
4answers
64 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 ...
2
votes
4answers
253 views

Inserting a line in a file only if this line isn't yet part the file

Total newbie to shell scripting, I am searching to create a script to automatically apply some custom configuration to text based configuration files. In the present case, I am searching to add 2 ...
2
votes
3answers
163 views

grep for all the lines that doest not have a particular word

I have a file fileA.txt Batman.plist Green Arrow.plist Hawkgirl.plist EOPrototypes.plist Person.plist EOPrototypes.plist EOJavellinPrototypes.plist Sinestro Slomon Grundy.plist Batman Beyond.plist ...
2
votes
1answer
51 views

How to match a particular form of optional sequence from a manual synopsis, including variations?

In this Q&A there is a reference to the manpages synopses being based "loosely" on the Extended Backus–Naur Form of metasyntax notation. It's interesting and serves as background. That being said, ...
1
vote
5answers
48 views

grep for text that may or may not be present

Lets say I have a file batman; robin; superman; password = ""; wonderwoman green lantern if I want to check if there is a password present, i.e there is something entered in the "" . here is an ...
2
votes
3answers
76 views

searching multiple strings in multiple files inside a directory and printing the string and corresponding file name where it was found

I have around 500 strings and I want to search for the files which contain them inside a directory and get the file names which contain the strings. So far I've been using: find -name 'LYFNRE.*' ...