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

4
votes
3answers
618 views

Search text in list of files

I'm trying to execute double search within files and return file names. I'm using find ./ -iname '*txt' | xargs grep "searchtext" -sl to find file names with 'searchtext' in them. Command is ...
4
votes
1answer
489 views

grep simply fails when used on a few files

I've been trying for about the past 30 minutes to get this to work properly. grep is not exactly the most difficult thing to use, so I'm somewhat baffled as to why this won't work. The files I'm ...
4
votes
1answer
13k views

Grep command, to remove lines containing a specified word

I want to use grep in the following way: grep -v "END","EXPDTA" 1bmz_model1.pdb > 1bmz_model.pdb I want the grep command to remove the lines which contain the words "END" and "EXPDTA", but all i ...
4
votes
3answers
3k views

How do I get grep color in the file names before each match?

If I run grep -ir "somethingtomatch" . from the current directory, I typically get results like this: ./some/path/file1.html: filecontent filecontent keyword filecontent ./some/path/file2.html: ...
4
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?
4
votes
1answer
68 views

Can I create a “file” that, when opened, actually gives the output of a command?

I've found myself in a couple of situations now where I'd like to have such a "file" that essentially runs a script whenever it's "opened", allowing me to "read" it's output. For example, I might ...
4
votes
3answers
8k views

Recursive zgrep not working

I have a directory hierarchy that contains numerous .gz files. I want to be able to recursively grep them for the string "foo". From what I've read online the following should work: zgrep -R -H ...
4
votes
3answers
4k views

How to use grep to match domain names?

I have a list of urls like: hxxp://url.com/subpage.html hxxp://www.url2.com/index.php hxxp://subdomain.url3.com/somepage.php ... How can I use grep to match the domain names only? All the urls ...
4
votes
3answers
3k views

How do you search for strings in a file which in turn is in an archive?

I can search through a number of files for a particular string by pipelining 'grep' and 'find' commands. Now, I have some 10 zip files each of which has archived a lot of text files. Is there any ...
4
votes
2answers
4k 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 ...
4
votes
2answers
401 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 ...
4
votes
1answer
228 views

Get additional data around match from grep

I'm wondering how to improve my grep use when being confronted with files with very long lines. Imagine something like "packed" JavaScript files that only have 1 line. Sometimes files like that spit ...
4
votes
2answers
1k 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
5answers
4k views

Using grep to find a string in files

How can I find a string in files in a directory, using file names beginning with the letter a. I also want to get the number of occurrences of this string from the grep I run. I tried this cat * | ...
3
votes
4answers
9k 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 ...
3
votes
4answers
22k 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 ...
3
votes
7answers
529 views

Bash operator < , > , | and grep / kill

As an exercise, I wanted to kill a process by command line using basic bash principles but i'm having some errors that i don't understand: ps -A | grep nautilus | egrep -o '[0-9]{4,5}' | kill 1) It ...
3
votes
2answers
4k 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
8k 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
2answers
2k 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
1answer
295 views

When piped with ls, grep in solaris is not working

I am using the below command in solaris ls -l | grep '*PROC*' But it is not working. I have many files that contain "PROC" in their name like "XREF_PROC.complete" but when I use the above command ...
3
votes
5answers
4k 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
5answers
5k 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
1k 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
6k 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
3answers
104 views

Filtering and splitting huge file based on column Windows

I have about 2 TB worth of data files formatted like 12/20/2015 somerandomdata 12/20/2015 somerandomdata 12/20/2015 somerandomdata 12/20/2015 somerandomdata 12/21/2015 somerandomdata 12/21/2015 ...
3
votes
3answers
144 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
81 views

How can I find a duplicate 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
2k 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
2answers
3k views

How to grep a line with a backslash at the end of the line?

I'm trying to grep a line with a backslash at the end of the line like: abc\ def ghij ... I hope it can grep the line "abc\". I tried the command below but they didn't work. grep -EHn "\\$" ...
3
votes
3answers
11k 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

Is negative look-behind supported in OSX grep?

I'm trying to do something like this: grep -r '(?<!notthis)butthis' ./* And I'm getting no results when some should be returned. Am I missing an escape? Or does OSX just not support regex ...
3
votes
2answers
1k views

Grep default color option

grep is one of the most commonly used command in linux. It feels to me that its basic feature to highlight the string you searched for on the output lines. this can be achieved by --color option. ...
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
167 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
338 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
588 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
382 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
2answers
812 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
6answers
2k views

Grep on the whole server in Ubuntu

I need to use the grep facility on the whole server. I tried the following: grep -r 'MyString' / grep -r 'MyString' /* However, none of these seem to work. Any suggestions?
3
votes
4answers
982 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
3answers
181 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
1k views

tar - exclude certain files

I wish to tar all files in a directory and its subdirectories that do NOT end in .jpg, .bmp, .gif, or png. So, given the following folders and files: foo/file.txt foo/file.gif foo/bar/file ...
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
240 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
2answers
30 views

How to get command output of “nvidia-settings” via command line?

the case at hand: nvidia-settings -q all | grep 'Attribute.*GPUCoreTemp' gives: Attribute 'GPUCoreTemp' (system5:0.0) 58. Attribute 'GPUCoreTemp' (system5:0[gpu:0]): ...
3
votes
1answer
74 views

how to open port in ubuntu?

I have open port 3003 that working correctly on all remote connection . when i type command: netstat -tupan | grep 3003 then it gives output ekodev@ezp:~$ netstat -tupan | grep 3003 (Not all ...
3
votes
2answers
133 views

grep -l output filenames with spaces

I want to loop over files with for f in `grep -rsl "foo" . `: do sed -i -- "s/foo/bar/g" $f; done; But since filenames contain spaces, a filename is split whenever a space is found. How can I ...
3
votes
2answers
702 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 ...