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
2k views

Command-line CSS selector tool

Question What tool (preferably for Linux) can select the content of an HTML element based on its CSS path? Example For example, consider the following HTML document: <html> <body> ...
3
votes
4answers
3k views

How to remove lines from large text file using bash

I got a huge text file (log file) in my CentOS which I would like to remove top part of, probably couple of thousand lines each day. (Or probably just split into two) I have search this site and ...
3
votes
3answers
3k views

How can I grep in source files for some text?

At the moment I'm using two commands, I'm sure there must be a better way... wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset wim@wim-acer:~/ffmpeg$ find . -name ...
3
votes
2answers
2k views

grep in Powershell

What is the mos easy/comfortable way to use Powershells built-in functions to emulate grep like behaviour? In scripts I use something like this dir "*.filter" | foreach-object{ $actfile = $_ ...
3
votes
2answers
15k views

Filter/grep some output only by certain column?

How can I filter some output only by certain column? I need something like this: tail -f logs/access_log | grep -v "200" --only-in-column=1 So I want to see only lines that don't have string '200' ...
3
votes
2answers
4k views

How to search a text file for strings between two tokens in Ubuntu terminal and save the output?

How can I search a text file for this pattern in Ubuntu terminal and save the output as a text file? I'm looking for everything between the string "abc" and the string "cde" in a long list of data. ...
3
votes
5answers
4k views

grep -r not working on Solaris

How can I do recursive grep on Solaris? When I tried, I received this error: -r: invalid option.
3
votes
3answers
921 views

Regular expression and grep not working

I have the following regular expression: ([:digit:]{4})-([:digit:]{1,2})-([:digit:]{1,2}) It should get dates in this format: 2010-12-19 And I am using it on filenames that look like this: ...
3
votes
2answers
3k views

grep for file content but return the filename

I need the GREP syntax for the following task (am in a LINUX OS): querying ALL files in the CURRENT directory which contain STRING but only listing the FILENAMES which contain a match. Thanks!
3
votes
1answer
5k views

How to set line length limit when using grep (Filter result by line length)?

The use case is that I am searching for a particular CSS attribute in a directory of HTML/CSS/JS files (including sub-directories). Some one-liner JS libraries also have the CSS attribute that I'm ...
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
98 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
66 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
1k 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
784 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
104 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
240 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
489 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
291 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
3answers
4k views

regex : does not begin by “pattern”

I have a lot of lines in my LIST file and want to list only lines whose name does not start by (or contains) "git". So far I have : cat LIST | grep ^[^g] but I would like something like : #not ...
3
votes
1answer
2k 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
530 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
2answers
4k views

How to grep to check if strings is not there in a file (in linux) and also the case of multiple strings?

I want to search if "ack_enabled not defined" is not there in a particular file all_defs.txt and return something, by which i can understand that the string is not there. Can anyone tell me how to do ...
3
votes
3answers
170 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
3answers
2k 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
188 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
1answer
2k views

Pipe grep exit code away

When I need to suppress some kind of output e.g. foo | grep -v bar But foo gives sometimes only: bar bar bar... grep will return -1. How do I transform the exit code 1 to 0?
3
votes
4answers
675 views

Does Unix grep work faster with long or short search terms?

Is it faster to look for long or short search terms? Or does it affect speed at all? In other words, should you make search terms as exact as possible? There are more than 100 000 files and each file ...
3
votes
2answers
479 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
4k 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
185 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
260 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
753 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
2answers
592 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
3answers
173 views

how to select nth result on command line without using mouse

I got this alias for searching for a file recursively and case insensitive type fr fr is aliased to `find . | grep -i' and so let's say i'm searching for a file fr nsstring+util ...
3
votes
6answers
178 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
1answer
869 views

How to have grep print only the matching text plus X surrounding characters

I need something similar to grep -A and grep -B but for characters. In other words, I have a file with incredibly long lines, e.g.: [thousands of characters] mytext [thousands of characters] If I ...
3
votes
1answer
765 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
3k 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
212 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
467 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
1k 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
1k 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
4answers
167 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
1k 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
3k 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 ...