grep is a command-line utility that is used for searching text.
4
votes
2answers
28 views
grep “+” operator does not work
This
ls -l /var/log | awk '{print $9}' | grep "^[a-z]*\.log."
outputs this:
alternatives.log.1
alternatives.log.10.gz
alternatives.log.2.gz
alternatives.log.3.gz
alternatives.log.4.gz
...
3
votes
4answers
35 views
grep: how to show only one word after found one?
I would like to write a script to disable keyboard. I write xinput disable 13 as built-in keyboard's id = 13.
But what if the 'id' changes somehow? Then it won't work anymore. That's why I have to ...
2
votes
1answer
49 views
Output not redirecting to file
I'm experiencing weirdness (or rather showing Linux ignorance).
I want to learn the probability distribution of ping requests, so I thought I'd ping some random site for a while, grep the output to ...
0
votes
1answer
52 views
find -exec grep does not work
I need to use a find command in a script with ssh and grep together.
Something like this:
ssh user@host find /var/log -type f -mtime 1 -exec grep -i -F error warn {} \;
But it says, that there is no ...
2
votes
2answers
88 views
How to search for both within filename (find) and file (grep) using a single line of code?
I'm pretty sure I've done this in the past (and that an answer is out there somewhere), but can't remember right now.
I'm looking for a one-liner to search for (and return / echo) matches in both the ...
0
votes
1answer
42 views
grep list each file once
I'm looking some text in files , but three are a lot of files and searched text appears several times in one file, how can I receive a list of files that contains searched text with every file listed ...
15
votes
2answers
532 views
Why does this grep command not work?
When I try to use grep in this fashion:
service --status-all | grep network
It still lists all the services even though I piped it into grep to restrict it to the "network" string only
After ...
1
vote
1answer
40 views
How to run same query on multiple servers via the jump server
I have many servers like sdeuu1, sdeuu2, sdeuu3,.. etc.
I want to run a query on each one of them and the query is :
grep -i 'SponsoredLinksIFrame.jsp' /home/nextag/httpd_logs/access_log.1360* |
...
1
vote
1answer
65 views
Search files in subfolder and export results to file
I have a folder with hundreds of subfolders. I need to locate recursively within the subfolders those that don't have certain files inside (for instance *ch.pdf or *.jpg) and export the results to a ...
1
vote
0answers
76 views
find command does not find string in subfolders
I have a file structure something like this:
/apps/base/logs1
and
/apps/base/logs2
Both logs1 and logs2 folders have .log files with some other files as well.
I am trying to do this
From /apps ...
1
vote
2answers
77 views
How to use grep to find the next 7 characters after “temp1”?
how can i get "+45.0°C" if the following output was a file (http://paste.linuxthefish.net/4@raw)?
I can get it to one line by doing
sensors -A acpitz-virtual-0 > sen
grep temp1 ~/sen
but it ...
6
votes
2answers
148 views
grep : how to color 2 keywords?
I know how to grep 2 keywords using 1 command, but I can only manage to color one of them in output . Here is my command:
grep 'keyword1' file.log | grep 'keyword2'
Only keyword2 is highlighted. ...
1
vote
1answer
79 views
grep command not returning all results
I am running the following command but not all files that I know have this string are being returned and I cannot work out why. Specifically the apache log files which are under this path are not ...
0
votes
2answers
51 views
In termninal, how can I find 1 phrase, in multiple files containing the phrase multiple times?
Trying to change the first background-color following the "body {" style, from whatever it is to "background-color: #000000;" in seven different stylesheets.css files. Also each .css file contains ...
8
votes
7answers
3k views
How to move multiple files at once to a specific destination directory?
I got a bunch of files in some directory (along with many other files) that I want to move.
Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep ...
0
votes
1answer
86 views
I'm unable to use grep to find strings in a file?
As i use grep
E.g: grep -iL or -ir /directoryname
It just displays all the file-names and when i opened them it doesn't have the relevant specified string in it. I want to know does grep really ...
16
votes
3answers
1k views
How to list content of all .zip files in a folder and grep for a specific file?
I have 348 zip files and I want to find a file that is in one of the zip files, unzip -l doesn't work with wild cards?
How can I list content of all .zip files and grep through the merged list of ...
5
votes
2answers
221 views
Grep through subdirectories
Add a string to a text file from terminal
I've been looking at this thread. The solution (number 2, with ls grep) works perfectly for files called .txt in the current directory. How about if I wanted ...
0
votes
0answers
121 views
Grep only shows last match
I've got a problem with grep.
When I use it as followed, it only shows the last match in every line and what follows after it.
For example:
If I use
tail -F example.log | grep -a -i -e "word1" -e ...
6
votes
1answer
120 views
Highlighting with grep doesn't work in Xterm
I've got a problem with Xterm.
When I use the command
tail -F example.log | grep -a -i -e 'examplestring'
in Xterm the "grepped" strings aren't highlighted in red like they would be in the normal ...
8
votes
6answers
251 views
Alternatives for 'egrep -o “success|error|fail” <filename> | sort | uniq -c'
I sometime need to check some logs and I do this with this command:
egrep -o "success|error|fail" <filename> | sort | uniq -c
Sample input:
test error on line 10
test connect success
test ...
1
vote
2answers
304 views
Using grep to find a string
I am trying to locate a file that (should) contains the string "1896.345", somewhere under /home/dir/.
Any ideas of how I can do it? Thanks
3
votes
2answers
824 views
How Do I fetch only the numbers in grep?
I have file like this :
other lines . . .
blah blah blah (:34)
I wish to find the occurrence of numbers in the above file. I came up with :
grep [0-9] filename
But that is printing the ...
2
votes
4answers
157 views
How do I find matching filenames in a directory listing?
I have bunch of ISO images in my hdd and I have their whole content listed inside a text file in the following format:
<immage>.iso, <dir structure>/<filename>.<extension>
...
1
vote
1answer
133 views
Right way to colorize ls?
Sometimes ago, I used Ubuntu and had colorized ls, grep "out of the box". Now I install KUbuntu and ls is plain text by default.
I tried to discover something about it and notice that there is ...
0
votes
2answers
279 views
How do I copy files that I just searched for via the command line?
Using Ubuntu 12.04 I need help on copying files that were returned from a search with grep .
I have many pdf files, so to filter specific named files I am using General grep command as
follows.
...
0
votes
1answer
608 views
How can I recursively check folders with flac files for corruption?
Something caused to damage some of my flac files, and to find out which ones I need to rerip, I would like to get a list containing only the damaged files.
How I do it now: Open a terminal in a ...
0
votes
1answer
264 views
grep and cut in a cue file + mkdir creates a directory name with a question mark
I do this:
var=`grep GENRE Billy_Cobham_-_Drum_\&_Voice_2.cue | cut -d ' ' -f 3`
mkdir $var
The file.cue interested line is:
REM GENRE Funky+Jazz
When mkdir creates the directory, the ...
1
vote
2answers
381 views
grep invalid option on ubuntu
I've already removed and reinstalled grep on Ubuntu but still the same error persists.
Whatever grep command I type I always see the following output:
grep: invalid option -- '='
Usage: grep ...
0
votes
1answer
83 views
How do I grep audio/video frame time indexes from an XML file?
I have a xml file like this:
<field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
<field ...
2
votes
1answer
87 views
Why does the --include switch in grep behave differently when both machines are on 11.10?
I have used the same following commands (in xterm) on two machines of the same ubuntu (11.11-64bit).
grep "jars2deploy" --include=*.xml ./* -r
However, one machine A only search for xml file, as ...
0
votes
1answer
207 views
Attempting to GREP details of a Java error
I'm running Ubuntu 11 and I'm having some issues with grep.
I have a shell script (see below) which essentially checks if a certain Java program of mine is running, if not it runs it. That part works ...
15
votes
2answers
1k views
How does this [t]ricky bracket expression in grep work?
I saw this one-liner recently:
$ ps -ef | grep [f]irefox
thorsen 16730 1 1 Jun19 ? 00:27:27 /usr/lib/firefox/firefox ...
So it seems to return the list of processes with "firefox" ...
2
votes
2answers
1k views
How can I recursively search for directory names with a particular string where the string is only part of the directory name
How can I recursively search for directory names with a particular string where the string is only part of the directory name?
For example:
the directory name is "8.0.3-99966_en", but I want to ...
1
vote
1answer
1k views
Search for a string recursively whilst in current directory
I want to search all files recursively from the directory I am in for a particular string.
I tried grep -r -i my_string
and I tried it in a test folder with two tiny files but it wouldnt find the ...
2
votes
1answer
657 views
Grep for a word in a file and show below and above lines too? [duplicate]
Possible Duplicate:
How to grep 2 or 3 lines, one containing the text I want, and the others just below it?
Say I have a file. I want to find a particular word in that file and show the ...
0
votes
1answer
229 views
ZGREP - Searching multiple, precise files
I'm trying to search multiple zipped files from a single directory. I'm using zgrep to currently search through either one individual file or all based on a wild card character. Here's what I'm ...
2
votes
2answers
489 views
Grep for contents between two markers with newlines
Just curious if there's a way I can show the output between two markers?
I was trying grep -r "<cron_expr>.*</run>" * but it doesn't seem to be returning as
expected. Which is to say its ...
4
votes
1answer
84 views
Custom GREP with asterisks and anchors?
I have lots of EDI files (which is pretty much a single line of gibberish text) that are about 300mb/pcs.
I'm looking to pattern matching this:
`*UP*605284466346 {lots of other stuff inbetween with ...
1
vote
1answer
2k views
How to find a folder on my server with a certain name?
I have a directory somewhere on my server wth the name "exampledocs". I tried to find it's location using:
ls -d */ | grep -E 'exampledocs'
and
find * -regextype posix-extended \-regex ...
0
votes
1answer
813 views
Missing php.ini after apt-get install php5
I just installed php5 as root via apt-get install php5, and for whatever reason I can't find my php.ini file.
Running locate php.ini or ls /etc/ | grep php.ini both yield no results.
Is there ...
0
votes
2answers
158 views
Cat a command to file
My bash script does many things, among which creating another script. I would like to have the following line to be executed from within a script. But it does not work (grep is executed instead of ...
1
vote
1answer
302 views
How do I parse emails with Mutt?
How would I go about parsing new message subject lines non-interactively using Mutt?
Mutt is already configured and fetches mail from our Exchange server.
What I'd like is for an action to be ...
1
vote
2answers
973 views
How to use text extracted from the “grep” command as an argument in a bash script?
I have a file called "krylov_methods", which has text like this:
cg - preconditioned
cgne - normal equations
nash - cg subject to constraint
stcg - another method for constraints
gmres - ...
0
votes
3answers
290 views
Filter results into a usable variable
I run the following command:
sudo iwlist eth0 scan
and get output that looks like this:
Cell 01 - Address: AB:CD:EF:12:34:56
ESSID:"name"
Protocol:IEEE 802.11g
...
2
votes
2answers
537 views
How do I use grep to find all the zip files in a directory?
I have a directory with over 1000 files, and a few of them are .zip files, and I want to turn them all into .tgz files.
I want to use grep to make a list of file names. I have tried "grep *.zip" to ...
4
votes
2answers
970 views
Is there a way to do a ' ls -R | grep “aname”* | rm; to remove multiple files in multiple directory
I have installed (compiled) emerald. The command make uninstall didn't work (there is no makefile as it is just a script). So I decided to remove the file manually. But there were a lot of files.
...
11
votes
6answers
543 views
How can I grep through tab completion possibilities?
When I press tab in a console I get this output
Display all 2957 possibilities? (y or n)
Is there any way to use grep on these 2957 possibilities? I would like to search for all commands with ...
1
vote
3answers
696 views
grep for string not preceded by another string
Is it possible, using grep, to search for instances of John Smith but exclude instances of Mr John Smith?
2
votes
4answers
3k views
Using grep, awk, etc. to filter command output
I'll use route as an example.
route -n
The above outputs routing information. The top row is your active connection. I can manipulate the output to only the second column by doing:
route -n | awk ...

