grep is a command-line tool for searching text patterns in files
1
vote
3answers
52 views
| Grep, Find which file the strings came from
I have a set of PDFs, and I am running
strings * | grep message
This returns the strings containing that method, is there anyway I can get grep to tell me which file it is from?
2
votes
2answers
26 views
Search class names in jars
I'm using this command to search *.jar files for java classes, and I only get the name of the jars that contain those classes:
grep -ral --include=*.jar SignonEJB .
How can I also get the class ...
1
vote
2answers
119 views
Unix command for pattern matching
I want to count the number of words and print the matched pattern lines which matches exactly with following pattern:
abc-ERROR:
The input File contains:
# abc-ERROR: xyxxkkfgfr
# def-Error: ...
6
votes
4answers
2k views
Number of files containing a given string
How can I count the number of files (in a directory) containing a given string as input in bash/sh?
2
votes
2answers
85 views
Tail -f piped through grep not outputing to file, but outputs to console
I'm using the following command
tail -f /mydir/myfile | grep "searchterm" >> outfile
Without the -f it works fine, but with the -f, which I need, nothing is written to the file. The ...
2
votes
2answers
39 views
How to find files with a certain subpath?
I need to find all xml-files that are placed in folders named config. Also config must be somewhere under a folder named trunk. For example, I am interested in all files like below:
...
9
votes
7answers
6k views
grep pdf files?
Is there a way to search pdf files using the power of grep, without converting to text first in Ubuntu?
0
votes
1answer
51 views
How do I redirect output from the find command (that uses grep) to a log file?
Consider the code to search for all files containing the pattern "search string":
bash-3.2$ # The below find works fine..
bash-3.2$ find . -type f -exec grep -il "search string" {} \;
bash-3.2$ # But ...
4
votes
3answers
735 views
shell script to read from multiple files in parallel
I need to write a script that runs parallel and looks for a string in multiple files. I tried a lot of options but they slow down the speed of my processor.
44
votes
8answers
2k views
How can I prevent 'grep' from showing up in ps results?
When I search for some process that doesn't exist, e.g.
$ ps aux | grep fnord
wayne 15745 0.0 0.0 13580 928 pts/6 S+ 03:58 0:00 grep fnord
Obviously I ...
2
votes
2answers
236 views
xargs grep suggestion
grep -v "\<Swap" instruments.log | awk '{ idx=index($0, "MasterId="); masterId=substr($0, idx+length("MasterId=")+1); masterId=substr(masterId,1,index(masterId,"L")-3); print masterId; }' | xargs ...
3
votes
1answer
73 views
How can I keep color codes with grep input?
It I grep something twice:
... | grep foo | grep bar
It seems foo is not highlighted.
Infact, it seems grep removes colorcodes from its input; Any way to prevent this?
1
vote
3answers
452 views
Help with a find command
I have a bunch of directories. Inside these directories is a cover letter and a zip archive of work. I wanted to run a quick and easy query to open up all the cover letters so I can decide if it's ...
1
vote
2answers
61 views
Split using sed
I have to split
[X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000
at the pipes and output those line whose 2nd and 3rd argument are different.
0
votes
1answer
47 views
How to ask for specific parameters with grep?
I need to look in /usr/share/dict/words for a 5-letter word that starts with d or D, followed by a lowercase vowel, and ends with s. I have tried everything but to no avail.
0
votes
1answer
71 views
Search low values in linux files
I am working with mainframe files and it seems that the low values (x'00') exists in the records in the file which throughs off my import for fixed block
Does anyone know how to eliminate this ...
3
votes
1answer
78 views
Understanding grep --label=
I am looking for an explanation how grep --label=LABEL works: Maybe somebody can give me an example [or two] on what --label= is for.
I understand what grep and zgrep are supposed to do – the ...
1
vote
2answers
51 views
linux + match IP ADDRESS with 3 octets or with 4 octets
how to match IP address with 4 octets or with 3 octets in one command?
target - match xxx.xxx.xxx or xxx.xxx.xxx.xxx ( syntax should fit for Linux and Solaris )
how to merge the following commands ...
6
votes
3answers
1k views
What is the difference between grep -e and grep -E option?
I am trying to understand the difference between grep -e and grep -E. Now from grep manpage I got:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (see below).
...
25
votes
4answers
3k views
Convince grep to output all lines, not just those with matches
Say I have the following file:
$ cat test
test line 1
test line 2
line without the search word
another line without it
test line 3 with two test words
test line 4
By default, grep returns each ...
0
votes
2answers
53 views
Grep to search directories for patterns inside a text file
I have a file where it contains a list of search patterns (searchPattern.txt). Its contents is similar to the contents below where there are 3000+ of them.
123456
234567
345678
.
.
.
What I wanted ...
4
votes
1answer
36 views
Printing Latex source with a2ps
When I try to print out latex source code with
a2ps somefile.tex
I get error messages from egrep like
egrep: Das Ende des angegebenen Intervalls ist nicht gültig
which translates to "the end of ...
1
vote
2answers
84 views
Fast utility that indexes files/directories on centos 6 for faster searching through the filesystem
I need to often search a large directory structure (with 1 G / 13K files of data). find / grep take a lot of time. Is there any utility (or can one make an index of these files) for faster searching.
2
votes
3answers
78 views
Very strange behavior with grep and IFS
I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character...
This is the script sample :
OLDIFS=$IFS
IFS="\\n"
i=$(grep -ril $1 *)
echo $i
IFS=$OLDIFS
...
4
votes
2answers
2k views
Can grep return true/false or are there alternative methods
I'm trying to write this script for an assignment - it's only the second one I've written so bear with me.
As a part of this script, I need to be able to check if the first argument given matches ...
0
votes
3answers
89 views
For all files that does not contain a string, prepend a string to the file
I am trying to iterate through a list of html files, check to see if {% load static from staticfiles %} exists in the file and if it does not exists, prepend {% load static from staticfiles %} to it.
...
4
votes
3answers
2k views
Search for values in 2 columns from CSV
I have a csv files with say 20 odd columns.
I need to get the 14th and 15th column values where value in 14th column is say "VALUE1" and value in 15th column is "VALUE2".
My condition gets satisfied ...
1
vote
2answers
37 views
Search and replace full line in recursive files
I'm using:
grep -n -H -o -R -e textword .
List all file recursively under directory '.' with string 'textword' and show the file, line and only portion matching.
I need to remove lines that ...
6
votes
4answers
3k 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 ...
3
votes
2answers
74 views
How to adjust column width in Linux command output
When I used this command on Red Hat Linux
/usr/sbin/ss -i
I get the following output below:
State Recv-Q Send-Q Local Address:Port ...
5
votes
3answers
201 views
difference between .* and * in regular Expression
I've a file named "test" that contains
linux
Unixlinux
Linuxunix
it's linux
l...x
now when i use grep '\<l.*x\>' , it matches :
linux
it's linux
l...x
but when i use grep '\<l*x\>' ...
2
votes
1answer
167 views
Web front-end to find/grep/ack
In my lab, we are trying to build a web that allows the user to enter queries for find, ack, grep on a specific directory. The web would return an HTML with a table of a list of clickable files (click ...
3
votes
2answers
53 views
Can I make grep treat escaped multiline as a single line?
How can I make tools like grep treat multilines escaped with a backslash as a long single line?
Let's say I have some files that looks like this:
testvar=test1 \
test2 \
test3
...
1
vote
3answers
88 views
Trying to remove all ids from an HTML file with grep
I'm trying to remove all id=" "s from an .html file but I'm not sure where I am going wrong. I tried using regular expressions but all I am getting is the .html file rendering in my Ubuntu terminal.
...
7
votes
6answers
1k views
Is there any alternative to grep's -A -B -C switches (to print few lines before and after )?
grep -A 2 -B 3
prints 2 lines after the grep string and prints 3 lines before.
grep -C 3
prints 3 Lines before and 3 lines after
Unfortunately, the grep I'm using does not support these ...
2
votes
4answers
759 views
cut / grep and df -h
How can I grep or cut the "173G" under "Verf"?
I need this for Unix scripting in school.
jonas@jonaspc:~/$ df -h /dev/sda2
Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/sda2 ...
4
votes
3answers
76 views
Uniquely identifying java processes with same name
I have two java processes which run using the same file name, MyApp.jar (for example).
/usr/java/latest/bin/java -jar MyApp.jar
These jars exist in different places and use different ...
3
votes
1answer
91 views
Output of `java -version` not matched by grep or awk
On my Linux machine, it isn't clear to me why if I do the following then I don't get only the version string ("1.5.0_32").
# java -version | grep version | awk '{print $NF}'
java version "1.5.0_32"
...
0
votes
1answer
36 views
(e)grep and atomic grouping [comprehension question]
I am trying to understand the correct use of »atomic grouping« a.k.a. »independent subexpressions« a.k.a. »non-backtracking subpattern« [this are the terms I found ...
1
vote
3answers
209 views
Newbie struggles with grep, sed, awk to filter html
I am a beginner linux user, trying to teach myself how to use linux tools on a cygwin install. I decided to make up a project to try to teach myself the basics of shell scripting and simultaneously ...
3
votes
2answers
109 views
greedy and lazy regular expressions (comprehension question)
I am teaching myself regular expressions, and I got stuck at »greedy« vs. »lazy« repeatings.
What I found out so far is that
»greedy« means that the RegExp ...
10
votes
6answers
324 views
How to find files with 100% NUL characters in their contents?
What is the Linux command-line command that can identify such files?
AFAIK the find command (or grep) can only match a specific string inside the text file. But I want to match whole contents, i.e. ...
2
votes
2answers
83 views
add “#” in begining to selected lines in File
Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B
File A
abcd
abdc
sdfg
asdfa
jon
ram
File B
jon
abcd
grep file B from file A and add "#" ...
2
votes
1answer
61 views
How can I get grep to work with “->” as the pattern?
I have this text in a file called temp:
-rw-r--r-- 1 root root 15776 Oct 15 2010 dnd-copy
-rw-r--r-- 1 root root 15776 Oct 15 2010 dnd-link
-rw-r--r-- 1 root root 15776 Oct 15 2010 dnd-move
...
2
votes
5answers
3k views
make grep output without trailing newline
Please consider this snippet:
X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* //p')
I want to put last word in a variable if some pattern condition is matched for lines in arbitrary text file
...
-8
votes
1answer
61 views
can anyone help me with this sed and grep? [closed]
(a) SED
Given a file, replace all the sequences of 4 or more digits with the
word "cat".
(b) GREP
Given a file, display all the lines starting with the word "cat" and
ending with the ...
1
vote
1answer
77 views
What is a sure fire way to find all files and/or path that contains 2 keywords?
I was doing a
find . -iname '*sitesearch*' | grep demo
because I know the file should be some/path/SiteSearch/demo/SiteSearch.html, but it turned out a person put the file in as ...
1
vote
1answer
61 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 ...
0
votes
3answers
129 views
Regular Expression for finding double characters in Bash
I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash).
Main Question: Is there a simple way to look for sequences ...
1
vote
2answers
73 views
Confused about inverse grep
So, when you use inverse in grep (egrep -v), this literally means the output is shown upside down (flipped over)?
I think I was more confused when I saw the following examples
$ egrep -v '\ ' ...



