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

learn more… | top users | synonyms

2
votes
1answer
53 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
287 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
76 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 ...
1
vote
2answers
426 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
99 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
173 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
271 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
41 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
114 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
95 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
39 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. ...
6
votes
3answers
239 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
113 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
277 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
171 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
58 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
54 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
235 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.*' ...
1
vote
4answers
92 views

Getting data under or above a line

This is my file: print energy 1 end Local net energy (PE 0) = 1.635393034217E+05 kJ/mol Global net ELEC energy = 1.635393034217E+05 kJ/mol print energy 2 end Local net energy (PE 0) = ...
6
votes
8answers
918 views

Grep rest of line…after match

I have a file containing only two lines, with the following structure: $ cat /tmp/pwpower.log 000D6F0000D34227, -114.10 000D6F0001A405C4, -130.09 The values are power values of my solar plant. ...
2
votes
5answers
210 views

grep change of line followed by a variable

I have a file of the following form (with '-' serving as delimiters), and I want to find the appearance of a number only when it follows a delimiter. I suppose it's a concatenation of grep '-\n' and ...
-4
votes
2answers
94 views

String pattern searching [closed]

I'm new to linux. I want to be placed as a System Admin. I attended an interview at Amazon. They asked me to write a cmd to find the string that starts with 's' and ends with 'a' in a file. I jz know ...
6
votes
2answers
401 views

fastest way to grep jar file for a particular name in it?

I am trying to find all the jars which has spring in its name. I am working with windows and using cygwin to run the linux commands. Does my below command looks right? find . -name "*.jar" -exec jar ...
0
votes
3answers
50 views

how to export all numbers that are unique in few text files into another file?

I have a.txt,b.txt,c.txt. Each has different numbers as below: a.txt: 12 14 111 1 15 2 b.txt 12 18 22 23 1 2 c.txt 12 14 15 16 17 1200 The output should contains all the numbers from ...
0
votes
4answers
100 views

grep to see if a line ends with a particular string

Hello I have a file that has a lot of lines that end with main.css">, and some of them are repeated. I want to keep only one copy of these lines and delete the repeated line. Could I use grep to ...
4
votes
3answers
105 views

How do I combine the -v and -B switches in grep?

I have a list of currently installed kernels, and I'm trying to grep out both the currently installed kernel and the previously installed kernel. For this example, linux-image-3.2.0-60-generic is the ...
10
votes
5answers
6k views

How do I recursively grep through compressed archives?

I'm trying to find out what modules use Test::Version in cpan. So I've used minicpan to mirror it. My problem is that I need to iterate through the archives that are downloaded, and grep the files ...
1
vote
2answers
325 views

Aix grep wildcard not working

I have a file called message that has the line CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758 I am doing a grep (Platform is AIX 6.1) grep ...
0
votes
2answers
114 views

How can I grep for broken HTML tags?

I want to grep through all my HTML files and see if I have any bad tags there, example <br> , <hr> and so on, that is the I want to see what tags are not closed in the HTML file. for ...
7
votes
3answers
4k views

how to count total number of words in a file?

I am looking for a command to count number of all words in a file. For instance if a file is like this, today is a good day then it should print 5, since there are 5 words there.
2
votes
5answers
201 views

how can I print the Nth and the Mth line above or below the matching line with grep?

Let's say I have a well-structured text file with following content(no leading line numbers): 1 Mon Jun 9 00:11:47 CST 2014 2 eth0 Link encap:Ethernet HWaddr D4:BE:D9:F5:5C:0E 3 ...
0
votes
3answers
52 views

How do I match a string with symbols in a grep-kind of way? [duplicate]

I have a file with this contents (or similar): # cat /var/www/htpasswd foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/ and I'm trying to verify the presence of an entry in it, by matching it, like this: ...
2
votes
3answers
668 views

GREP / SED or AWK: Print entire paragraph in a file on pattern match

I have a file with hundreds of paragraphs of around 15 lines each. I need to search for a pattern, say Occurance: 1. If this pattern is found in the para, I need to print the entire paragraph. Note ...
1
vote
4answers
2k views

Using sed/awk to remove anything after first space

aaaaaaaa 09 bbbbbbbb 90 ccccccccccccccc 89 ddddd 09 Using sed/awk/replace, in the above text I want to remove anything that comes after the first space in each line. For example the output ...
9
votes
2answers
433 views

Filter output of command by color

I am running a utility that doesn't offer a way to filter its output. Nothing in the text of the output indicates that a particular function failed but it does show in red. The output is so long that ...
0
votes
1answer
54 views

How to output the lines of a file after find and a grep?

Hello I want to output ERROR messages from logfiles from the current date. First I search for the logs of today with specific prefix: find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" ...
0
votes
2answers
40 views

How can I search filenames which are starting with xy_* and are created/edited today?

Hello I´m currently trying to search for logfiles which are starting with xy_Number and are created/edited today(not last 24 hrs). I tried: find /home/USER/logfilesError/ -maxdepth 1 -type f ...
2
votes
3answers
182 views

Find a pattern with no repeated numbers in egrep

I need help finding a regular expression to match all digit sequences which has no repeated digit. Example: 198345 -> matched. 198315 -> not matched (1 repeated twice ) How can I achieve this in ...
1
vote
3answers
1k views

Find files containing one string but not the other

I am in a folder with lots of .txt file, I would like to find all the files which contain stringA, but don't contain stringB (they are not necessarily in the same line). Does anyone know how to do ...
2
votes
2answers
989 views

Some UTF-8 characters not being recognized by grep or sed

Trying to determine all characters in a file. The file sample consists of: a eɪ abandon əˈbændən ability əˈbɪləti able ˈeɪbəl able ˈeɪbl abortion əˈbɔrʃən abortion əˈbɔrʃn about əˈbaʊt above əˈbʌv ...
1
vote
3answers
303 views

GREP for Processes by Directory and Kill it

I'm trying to grep for processes that originate from the /Applications/ directory (to kill them), but my grep command keeps catching some false ones as well. What am I doing wrong here? $ ps -ef | ...
6
votes
6answers
436 views

Check if a variable contains only what I want, and nothing else

I'm writing a script to build a software from sources, and there's a --platforms option. I would like to allow the user to select multiple items, but I don't know how to prevent them from making a ...
1
vote
2answers
63 views

grep a keyword from Mplayer output and send the rest to file

I am using mplayer. I want to send everything to a log file (/tmp/server.log), but I want the Volume output to be written to the terminal. I have seen that there is a way to split the output with tee, ...
1
vote
1answer
65 views

Using `tac` on zipped files

tac unzipped.log | grep -m1 pattern works perfectly fine but I am not able to use the tac command on zipped files. tac zipped.gz | zgrep -m1 pattern returns nothing. Is there anyway to use tac ...
3
votes
3answers
205 views

How can I get the first column of a 300GB txt file?

let me first explain my problem in detail. It's actually pretty simple. I have a huge .txt file, 300GB to be more preciese, and I would like to put all the distinct strings from the first column, that ...
2
votes
3answers
147 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
6
votes
10answers
1k views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
0
votes
4answers
300 views

Search for a Value only in one column w.o using awk, sed, or perl

I have a file that looks like this : Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles Karen Thompson Sales Peter RobertsonPARTGolden ...
1
vote
3answers
140 views

Returning only the portion of a line after a matching pattern (Unix)

I have a parent folder (abeps) which contains several sub folders (1,2,3....25) where output file is located, one in which - all are the same name (opt.out). In this files there is an unpredictable ...
1
vote
2answers
231 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...