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

learn more… | top users | synonyms

2
votes
2answers
26 views

Live replacement, while viewing log using LESS

It's very convenient to monitor logs using less command - you see what is going with your system as it happening. The bad thing is that my logs are optimized for grep tool: each atomic action is ...
0
votes
1answer
16 views

find file read it and search for specific identifier

I'm trying to find out in what files some specific identifiers are being used. I know the file's name and know the identifier, therefore I use the following command to achieve my desired result: find ...
2
votes
5answers
109 views

Remove multiple lines after a pattern match but only after pattern match

I am trying to remove all instances of a pattern match from a file if it matches a pattern. If there is a match, the (complete) line with the matching pattern and the next line get removed. The next ...
1
vote
2answers
49 views

grep contents of files based on a list of files

Running CentOS 6.5, qemu-kvm. I have a script which builds a list of running VM's. I want to pull information from those .xml files of only the VM's that are running. cat /dev/null > ...
7
votes
7answers
353 views

How can I “merge” patterns in a single line?

I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character? Now I am getting: pattern1 pattern2 ...
0
votes
2answers
33 views

grep command. '^1' won't work

ttys000 -bash: cat n_modified.txt 1 calibre library 2 desktop 3 documents 4 downloads 5 library 6 movies 7 music 8 pictures 9 public 10 ...
0
votes
0answers
19 views

How to get ids from xml file into mysql?

I've got 8 xml files and need to do some work on these records in mysql. What is a good way to get these IDs into mysql? <?xml version="1.0" encoding="utf-8"?> <Records> <Record> ...
2
votes
1answer
39 views

Grep does not seem to work properly for me

Command: LC_ALL=C fgrep -f /root/inputfile.txt *.txt > outputfile.txt inputfile contains this kind of stuff; -name1: -name2: -othername: *.txt (multiple files) contains things such as ...
3
votes
4answers
69 views

How to remove text matching specific patterns from a file

I want to compare two files to check for differences between them, fileA and fileB. fileA is like a template file and fileB is the file which I want to compare to it. Anytime I find a difference I ...
2
votes
1answer
23 views

Get each column which contains multiple spaces?

My file: subnet 172.25.10.0 netmask 255.255.255.0 { option domain-name-servers 172.25.10.9, 8.8.8.8; default-lease-time 300; max-lease-time 7500; range dynamic-bootp 172.25.10.10 172.25.10.30 ; ...
0
votes
1answer
34 views

Quote escaping struggle with grep and sed

I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
-4
votes
1answer
75 views

What command in bash to search for this string?

file.txt contains: aa=testing sss=whoiam bbb=findme What command do I use to search for testing and print it? Expected result: # you search testing
4
votes
1answer
62 views

unexpected output with grep

I am using pyrit. For those who dont know, pyrit allows among other things to check if a wpa handshake key is valid: pyrit -r file0.cap analyze when a file does not contain a valid key, here is ...
3
votes
2answers
77 views

Getting the combined count of all occurences of a string under multiple directories?

I have a (hopefully) interesting problem that I could use some advice on. I have a system that's essentially used for storing logs. It has a directory structure like: YYYY/MM/DD/hostname/ There are ...
4
votes
6answers
151 views

grep with a lot of files which contains a lot of lines?

Imagine we have a lot of huge(30000 line)files: a.2014-05-06, a.2014-05-07, a.2014-05-08 and so on. I know that we can grep a line with word using this command: grep "word" a.* First I guess this ...
0
votes
0answers
24 views

Get only files specified in egrep

I could to like ask how to get only the files that contains or match with this command [ "$(egrep -l 'GE.[100|120|140|159].' /home/test_dir/* xargs egrep -l 'EA.[NT|[HD|HS|QR].')" ]; My problem ...
4
votes
1answer
129 views

command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory

I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
6
votes
1answer
259 views

find words with all vowels in order from a file

I have a large dictionary file with 300,000+ words in it and I'm trying to find all words with the vowels aeiou in that order and have only exactly 5 vowels. My current attempt does not seem to be ...
-3
votes
2answers
55 views

Extract certain column from CSV files [closed]

I have a directory with a group of CSV files. All files have the same column headers. I need to extract values in a certain column from all files. The common part in files names is ...
0
votes
1answer
51 views

Print lines if pattern is not matched

Print lines of File 1 only if they don't contain patterns specified in File 2 Exemple: $ cat File_1 L1 pattern1 L2 pattern pattern2 L3 pattern3 pattern L4 pattern4 $ cat File_2 ...
5
votes
2answers
252 views

How do you get fgrep to find the literal “--help”?

fgrep --help | fgrep "--help" returns just the whole fgrep --help, how do I return just the lines that have the literal "--help" in them? The quotes don't do anything, nor does \-\-help.
2
votes
1answer
26 views

Grep patterns in selected lines

How to keep rows containing pattern 1 only if the next line contains pattern 2 and starts with pattern 3 ? Exemple: keep line starting with an A only if the next line starts with a B and contains ...
2
votes
2answers
64 views

Will grep go faster with line breaks?

I have some big files that I have changed into "standardized form", removing line breaks. I want to speed up greps on those files. I know that you can optimize grep by doing grep 'partofpattern' | ...
5
votes
4answers
207 views

How to replace m part of Lines with n part of Lines?

I have a file "test" like this: RewiteEngine On RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.7$ [NC] RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.8$ [NC] RewriteCond %{REMOTE_ADDR} ...
-1
votes
2answers
41 views

How to use grep to find all instances of one .txt file in another?

How would I use grep to compare if any line from one .txt document occurred in another? Further how would I use grep to find out the opposite? Would it be grep -v?
2
votes
4answers
58 views

Matching string with a fixed number of characters using grep

I am trying to find all 6 letter words using grep. I currently have this: grep "^.\{6\}$" myfile.txt However, I am finding that I am also getting results such as: étuis, étude. I suspect it has ...
4
votes
1answer
35 views

grep variable-length optional text

I would like to search for edge-anchored text that has a block of preceding optional text, any amount of which can be included in the match. For instance, supposing I am trying to find ^xyz but would ...
3
votes
1answer
46 views

How to export data in the terminal to a file (e.g. csv file)

I am a complete beginner in using Linux and I would like to know how to export a bunch of data in the command line to a csv or spreadsheet file (or even text would work). Right now I am simply using ...
3
votes
0answers
20 views

agrep with directionally biased penalties

I am using tre-agrep, an implementation of agrep, to perform approximate pattern matching. This utility searches for matches based on Levenshtein distance, and the user can configure the penalty ...
0
votes
1answer
18 views

For a given directory, how do I concatenate the tail end of recently modified files to a new file?

In case there's a better solution to the problem, my goal is to be able to quickly analyze ALL recent apache activity in /usr/local/apache/domlogs. The usefulness of this is when the server load is ...
0
votes
2answers
36 views

How to list similar lines?

The delimiters could be: " "; "_" INPUT: foo#foo_ehh113#The password of user 111 will expire within the next seven d foo#foo_ehh204#The password of user 111 will expire within the next seven d ...
0
votes
3answers
65 views

grep substring between quotes

Let's say I have a string like this: title="2010-09-11 11:22:45Z" How can I grep the date itself and disregard the quotes/title/Z? The file can contain more strings like: randomstring ...
5
votes
4answers
73 views

Search a pattern and print preceding lines starting with another pattern

I need to grep for a pattern and once I find it, I need to look for another pattern preceding that and print all those lines in between those. Better example: 1 a 2 a 3 a 4 a 5 a 6 b 7 c 8 d 9 xyz ...
7
votes
4answers
416 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 ...
7
votes
2answers
454 views

Why is `tac file | grep foo' (piping) faster than `grep foo < <(tac file)' (process substitution)?

This question was motivated by "Reverse grepping", about grepping a huge file from bottom up. @chaos said: tac file | grep whatever Or a bit more effective: grep whatever < <(tac file) ...
1
vote
3answers
65 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 ...
28
votes
4answers
2k views

Reverse grepping

Let's say, I have a really big text file (about 10.000.000 lines). I need to grep it from the end and save result to a file. What's the most efficient way to accomplish task?
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?
2
votes
3answers
61 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 ...
0
votes
2answers
98 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 ...
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 ...
1
vote
3answers
88 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 ...
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 ...
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 ...
2
votes
3answers
78 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 ...
0
votes
3answers
82 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 ...
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
62 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
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 ...