grep a Unix command-line utility which searches input passed to it for lines matching a regular expression, and prints the results.

learn more… | top users | synonyms

3
votes
2answers
4k views

Using find or grep to locate filenames with accented characters from a different encoding system (Windows to Linux)

I tried to tag late onto a question similar to mine on stackoverflow (Find Non-UTF8 Filenames on Linux File System) to elicit further replies, with no luck so far, so here goes again... I have the ...
3
votes
3answers
87 views

Regular Expression: how to match 'ab','ac' and 'a'

Now, I have three strings to be matched by a single re -- 'a', 'ab','ac' I suppose one correct re should be 'a[bc]?', but it seems not correct. What is the correct one? I try it in grep command. And ...
3
votes
2answers
5k views

Recursively list full absolute path of files with permissions in Linux

I have done a bit of searching online, and I am trying to find a way to recursively list all files with their absolute path and with their permissions. I want to do this so that I can grep out what I ...
3
votes
2answers
64 views

How can I find the other copy of an image file?

I have an image file, and I know there's another copy of it somewhere in a directory or one of its ancestors, but it has a different, unknown file name, and there are thousands of images in this ...
3
votes
5answers
2k views

Grep all files in a directory and print matches with filename

I have a list of log files that I create as part of a video encoding script that I wrote. I would like to search all of them and print out certain statistics from the encode - how fast they were ...
3
votes
4answers
931 views

grep not functioning correctly

I've been happily using grep for many years without any issues, but since today it quit working. During the past hour I tried this and that, but enough is enough, I'm posting the bastard here: On the ...
3
votes
4answers
1k views

Search for and print only matched pattern

I have some huge xml text files. I need to write a script to find and print a specific tag only. I tried sed and grep but they both return the whole line. Using SunOS 5.x, so not all linux commands ...
3
votes
2answers
455 views

How do I pipe output to date -d “value”?

I have a date like "2014-01-30 05:04:27 GMT", and if I run date -d "2014-01-30 05:04:27 GMT", the output is in my server's timezone ("Thu Jan 30 16:04:27 EST 2014"). With the use of grep and cut, I ...
3
votes
2answers
87 views

grep does not recurse

Whenever I use grep with gnuwin32's recurse option -r and include a glob pattern for files to search (e.g. *.c), no files in the subdirectories are searched. I am using the latest grep from gnuwin32. ...
3
votes
3answers
202 views

grep recursively to look for occurrence of a word in a particular file

I know about grep -rin 'text' /path/to/direcotry But I dont want to look up in all the files . I just need to check for occurrence of 'text' in all files named wscript. How can that be done ?
3
votes
2answers
455 views

How can I retain grep's match highlighting when piping find into grep?

If I run grep foo bar.txt, grep highlights each occurrence of "foo" in bar.txt. But sometimes I want to use find to determine which files grep searches. So I do something like this: find . -iname ...
3
votes
3answers
245 views

Bulk renaming files [duplicate]

Possible Duplicate: How can I mass rename files from the command line or using a 3rd party tool? So I have a series of files with the following format Their real file name followed by the ...
3
votes
1answer
1k views

Finding and deleting lines from all files recursively

I have managed to grep the occurences of a keyword by using grep "KeyWord" . -r -n -i -I but, the occurences of the KeyWord are too large. I just want to delete all the lines containing that word. ...
3
votes
1answer
477 views

Checking if any data exists on a presumably empty storage device

So, say you've completed a full pass of: dd if=/dev/zero of=/dev/sdX bs=1M Then, you'd like to make sure the destination has been really zeroed out (ignoring the confirmation messages from dd ...
3
votes
3answers
168 views

unix command to verify span of word in text

What unix command(s) can I use to determine the line span that a word appears in text? The "span" being equal to the line number of the last instance of a word minus the line number of the first ...
3
votes
1answer
737 views

Grep file in GVIM on Windows

On Linux, I sometimes see a list of all the lines which match a term with this handy command: :! grep -n "term" % However, I am now stuck on a Windows XP SP3 machine which lacks grep! Is there a ...
3
votes
3answers
1k views

how to find (grep) paragraph start with word and ending with other word and ignore new line?

I want to find a paragraph is a list of files. For example an SQL statement which looks like: upadte b_table set number = 100014 where id in ( select number_desc from t_table ...
3
votes
1answer
181 views

finding surrounding lines with grep

I know how to use grep to output a line that matches a string. But what if I also want to output one line above every line containing a matching string, how do I do that?
3
votes
3answers
3k views

how can I grep a hex value in string in a binary file

I have a binary file like this (open in emacs hex mode): How can grep if hex values '22081b00081f091d2733170d123f3114' exists in file? 00000000: 2b08 1b00 1418 0825 0407 3830 271d 170d ...
3
votes
2answers
407 views

ash scripting: space-containing variable refuses to be grepped

I am trying to run the script listed at http://talk.maemo.org/showthread.php?t=70866&page=2 on its intended hardware, a Nokia Linux phone running BusyBox ash. The script receives the name of WiFi ...
3
votes
1answer
1k views

Why doesn't ack recursively search all files by default?

From everything I can read ack-grep foo should search through all files in the current directory and subdirectories for the term "foo". However, the closest I can get is ack-grep foo * Which ...
3
votes
1answer
3k views

Matching a number sequence in grep

So I'm trying to match a year number sequence with grep and this should be easy. I'm just a bit stumped that my simplistic regex isn't working. What I'm doing is running a tool which archives some ...
3
votes
1answer
172 views

Faster grepping through lots of bulky text files

I have log files that are 500 mb each and there are 200 of such files. I need to grep certain patterns inside these files. But this takes up a lot of time! Is there a (open source) software that can ...
3
votes
2answers
247 views

Aren't egrep, fgrep supposed to be aliases to grep?

Since egrep is essentially grep -E I would expect it to be an alias that calls grep with that option. However on my system file `which egrep` shows it is an executable. Also egrep as an alias only ...
3
votes
2answers
700 views

Match exactly (and only) the pattern I specify in a grep command

Usually, grep searches for all lines containing a match for the pattern/parameter I specify. I would like to match just the pattern (i.e. not the whole line). So, if a file contains the lines: We ...
3
votes
1answer
568 views

FreeBSD flag to ignore permission errors when searching file for a string

Im using the following to serch for a string in all the files in a directory. grep -Flr --include "*" 'mystring' /modules/ Which works perectly fine and returns the files which contain the string. ...
3
votes
1answer
268 views

Using grep to filter output of a process

I'm using command | grep -v "JavaScript strict warning" to filter the output of a command (hiding warnings). The grep command works fine when I test it like this: $ printf "JavaScript strict warning: ...
3
votes
2answers
2k views

Efficient way to search string within file find and grep

I am searching all files containing a specific string on a filer (on an old HP-UX workstation). I do not know where the files are located in the file system (there are many directories, with hudge ...
3
votes
1answer
187 views

Strange execution time for recursive grep

I'm on a Linux Ubuntu machine, grepping a large number of files. Can anyone explain these timings? >time grep -nIr acct_margin * [... 3 results ...] real 0m0.555s user 0m0.400s sys ...
3
votes
2answers
374 views

find any script which is running for more than say 30 minutes in Linux System

Please share command to find any script which is running for more than say 30 minutes. in Linux System
3
votes
1answer
935 views

grep, xargs, sed to clean up PHP eval hack

I'm attempting to use the commands found on http://devilsworkshop.org/tutorial/remove-evalbase64decode-malicious-code-grep-sed-commands-files-linux-server/55587/ to clean up a PHP eval based hack on a ...
3
votes
2answers
200 views

Simple (?) Unix Grep Command

How do I recursively view a list of files that has one string and specifically doesn't have another string? Also, I mean looking inside the files, rather than the file names.
3
votes
2answers
944 views

Tool to fix file names starting with =_iso-8859-1… in .eml file names?

I have a folderful of E-Mails saved from an IMAP account that I dissolved. The file name is the subject line of each E-Mail. Now unfortunately, when a non-ASCII encoding is used, the subject line ...
3
votes
5answers
125 views

How to match everything from after the last YAML delimiter onwards

I normally use grep to search for a pattern in a string. However in this particular instance I have to identify a YAML header, also, it ends with a triple dash. My test.info file has the following ...
3
votes
4answers
126 views

Use different colors for every another grep

How can I configure grep so that I could highlight in color smarter? By using different colors? Problem: grep --color defaults to using red to highlight matches, but it still difficult to read for ...
3
votes
2answers
776 views

Continuously check netstat output for a particular program

I have a android emulator running on port 5554. I want to continuously watch the netstat output concerning emulator stuff. Right now I have to manually execute this command every time sudo netstat ...
3
votes
2answers
2k views

Getting rid of 'grep: line too long'

I used the following syntax in order to find the IP address under /etc (answered by Dennis Williamson on the Super User site), but I get the message grep: line too long How can I get it to ...
3
votes
1answer
62 views

Using grep on URLs not working

I've got a couple of text files (a.txt and b.txt) containing a bunch of URLs, each on a separate line. Think of these files as blacklists. I want to sanitize my c.txt file, scrubbing it of any of the ...
3
votes
0answers
100 views

ag (the_silver_searcher) not searching entire file - does it have an implicit maximum input size?

I have a very large plain text file (multiple gigabytes in size) which I need to search for certain strings. When using grep, I get over 11,000 matches of a string but with ag I get roughly 1,500. The ...
3
votes
2answers
891 views

Filter tail command through multiple grep commands to separate files

What I am trying to do is filter the output of one log file into separated log files based on a grep filter. tail -f test.log | tee >(grep "Error" > error.log) >(grep "Warning"" > warning.log) ...
3
votes
2answers
293 views

linux: is tree -i -f -L $depth supposed to be faster than find -maxdepth $depth?

I am querying specific directories to see if I find files with a specific pattern in them and I have been trying it with two different commands: Standard find command: find -L $unix_dir\*/ -maxdepth ...
2
votes
6answers
716 views

Under *nix, how can I find a string within a file within a directory?

I'm using ubuntu linux, and I use bash from with a terminal emulator every day for many tasks. I would like to know how to find a string or a substring within a file that is within a particular ...
2
votes
3answers
315 views

How to use grep to search for regular expressions themselves, without parsing them

grep . filename.txt This just returns all of the contents in filename.txt, because . is a regular expression that stands for any character. How do I use grep to search for periods, or other regular ...
2
votes
3answers
4k views

How to use grep to search for multiple options

How can I use grep to search for line with either 'res' or 'rep'? i try "grep -e res|rep" or gre -e "rep|rep" but that does not work.
2
votes
7answers
951 views

grepping large amounts of text

I have a few gigabytes of source code. using recursive grep for a term can take a while. I am using ext3. Is there a faster way? Would using find be faster and if so why? Would using a filesystem ...
2
votes
4answers
2k views

How do I write a script that sums the numbers in a file?

I'd like to sum up numbers in a plain text file. Is there somehow I can do this with a command or a bash script? Say I want to extract the number in a pattern that looks like this: … text text … ...
2
votes
7answers
177 views

strange behaviour of grep in UNIX

When I type the command $ grep \\\\h junk then the shell should interpret \\\\h as \\h - as the two pairs of \\ each become \ . grep in turn, should interpret \\h as \h as \\ becomes \, so grep ...
2
votes
4answers
7k views

grepping a substring from a grep result

Given a log file, I will usually do something like this: grep 'marker-1234' filter_log What is the difference in using '' or "" or nothing in the pattern? The above grep command will yield many ...
2
votes
4answers
6k views

Print line X lines before/after found line

I want to search for a particular string in a certain file. If I found the string, I also want to print the line X lines before (or after) that line. Can this with grep or awk, or do I need a ...
2
votes
4answers
1k views

How to grep for a line that has the same number you both need and don't need

This isn't at all easy to explain but easy to just show. I have lines in a file such as: 100Dollars 3 IP 200Dollars 3 IP 300Dollars ...