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

2
votes
2answers
2k 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 ...
2
votes
2answers
80 views

Opening search results with Vim ONLY if they exist

:) In my never-ending effort to get lazier, I am looking for a way to improve my "Open Grep/Ack-results in Vim"-snippet. What I'm currently using to open found files is: vim $(ack -il "pattern") ...
4
votes
1answer
80 views

Why does grep need a dot in a regex using '$'?

I though I knew grep, but maybe not. I want to find all lines in a file ending with ':' If I run grep :$ ~/greptester.txt but to my surprise, it gives no results. Sometimes I confuse '^' and ...
4
votes
1answer
374 views

Vim: How do you use external grep on windows to search for quotation marks?

For some reason I can't for the life of me figure out how to pass single quotation marks to external tools when using vim. For example, I might want to call Vim's external grep to search for the text ...
1
vote
1answer
502 views

What does `grep -n` option mean?

When I use find-grep in Emacs, this command is appeared. find . -type f -exec grep -nH -e {} + I searched -n option in man grep. Why is not there? And What does it means?
4
votes
2answers
70 views

Sort files with grep

I have a few hundreds of output files, of which some contain error messages. Lets say I want to automatically put all files containing the string "ERROR_1" in a "subfolder_1", and the rest in a second ...
2
votes
3answers
146 views

What does really mean null string?

I'm sure most of us know that when we want that some regex matches with a string at the begin of the line we must use "^" ... But, I'm trying to understand what really means "empty string at the ...
1
vote
1answer
456 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 ...
0
votes
4answers
106 views

Count lines with alphabet in linux

I have a file with a number of lines in a file filename. I want to count how many lines start with character 'a', with 'b' and so on in one go. What command i should execute.?
2
votes
1answer
104 views

How to grep through files which match a regex

I wish to search for keyword "test", in all files which are of type "*.spec.in" in the current directory recursively This doesn't work: grep -rn "test" ./*.spec.in How do I do this?
0
votes
3answers
94 views

Pre-pending to an output line of `tail -f file` if its contents match another file

Trying to cram all of the following into the title was hard, so this is what I really mean: I am doing a tail -F access.log to watch an Apache2 log in realtime. The first thing on each line is an IP ...
-1
votes
1answer
4k views

“ps -ef | grep java” using java program [closed]

I'm attempting to execute ps -ef | grep java through java program. Here is my code- // String sudoScript = "sh -c \"ps -ef | grep java\""; String sudoScript = "ps -ef | grep java"; try { ...
1
vote
2answers
1k views

Remove lines matching string in grep

I have some long configuration files to go through, and I would like to see just what is actually active in the .conf file, without any of the # tags. What can I use to output the lines without a # on ...
0
votes
1answer
566 views

only show running services using service --status-all and grep

If I do service --status-all I get something like this: [ ? ] webmin [ ? ] whoopsie [ + ] winbind [ - ] x11-common I want to show just the running ones ([ + ]) so I did service --status-all | ...
0
votes
2answers
188 views

Writing a single line command that interprets conditional output from pdbedit

I would like to run a command on a single line that will tell me if the flag is set for a user's password to be changed on next login. This command will interpret the output and return a true/false. ...
0
votes
1answer
170 views

Find a pattern in a line, and append that matched pattern to the same line

I'm trying to pull a job number out of notes listed in a csv, and then append that number to the end of the line, preferably through sed, awk, grep or perl (which I have installed in Cygwin. Here's a ...
4
votes
1answer
4k views

How can I avoid the “grep: Argument list too long” error?

I'm using Mac 10.7.5 and on a bash shell. I'm trying to find instances of a string in a group of files but keep getting this error Daves-MacBook-Pro:folder davea$ find . -name "*" | xargs grep ...
0
votes
1answer
2k views

Save result of a grep -c into a shell variable

How can I store the result of grep -c as an integer in a shell variable? This: check=sudo virsh list |egrep -c '\b[0-9]{2}\b' only gives me the number of matches and prints it on screen whereas ...
2
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 ...
0
votes
2answers
2k views

How to grep multiple strings on multiple files?

I am trying to grep multiple strings on multiple files. This is on Windows 7 x64, and I am using GNUWin32's flavor. I have grep.bat with this command: grep "string1\|string2\|string3\|string4" ...
21
votes
3answers
665 views

How to prevent a password or other sensitive information from being stored in the bash history when using grep?

I had to grep recently for a password that may have been saved in a file. I did not want that line to show up in the bash history. How can I prevent a password or other sensitive information from ...
1
vote
2answers
55 views

grep-like command that output context records

I'm looking for a grep-like command that outputs full records instead of a fixed number of context lines. For instance: grep -d record_delimiter PATTERN [FILE] Logic: split the FILE in records ...
1
vote
2answers
153 views

How do I extend unix “ps -ef” command to see more info

I need to grep process by information containing in CMD column, but this column strings is cut(limited) and needed info is lost. Please suggest how can I enlarge string size allowed for CMD column.
0
votes
2answers
287 views

Send HTTP request from server to another server and get the IP that replies

so I have to do this project, and I honestly have NO idea where to start. So basically, it will send a simple GET request to a web server, and then wait for a reply, and it will print out the IP that ...
0
votes
1answer
397 views

Running pdfcrack to include special characters in charset

I'm trying to recover a password from a PDF file using pdfcrack. I want to change the charset to include special characters. Can I use some kind of i/o redirect to feed the contents of a a similiar ...
0
votes
2answers
127 views

Linux output line numbers where string match appears

what I'm looking to do is boost the command I already have to return line numbers of where the specified string appears: grep -r -l -n -w "ePKI" /home/websites/www/* > /home/keywords.txt The ...
0
votes
1answer
113 views

How can I open a set of files in sublime based on their contents

I am trying to find all the files that contain a search term: grep -lir "Search" . and pipe that into sublime: grep -lir "Search" . | subl but all this does is open a single file in sublime ...
2
votes
2answers
518 views

Linux - Multiple service statuses with one command

I'm trying to retrieve a list of multiple service statuses in Unix. I'm using the service command: man page. The statuses all start with the transmission-daemon string, for example. I require the ...
0
votes
1answer
73 views

Search files for text matching format of a Unix directory

I am attempting to search through all the files in a directory for text matching the pattern of any arbitrary directory. The output of this I hope to use to make a list of all directories referenced ...
1
vote
1answer
348 views

Open all files in a VIM split window view with grep/ack command

I did a ack-grep on files that contain a string. I then want to open these files in a VIM veritcal split window view. How can this be done via the terminal?
-1
votes
1answer
170 views

Grep : Windows version, free alternative? [duplicate]

I am trying to source a tool for performing a search and replace of text files in a directory. I think this is similar to what grep does for linux. I was hoping to find a tool with a gui so I could ...
0
votes
1answer
289 views

Grep get everything except matching

Lets say I have a text file that says: Hello my name is agz. I am asking a question that is important. If i type: grep -v "is" /path/to/file, I should get no output because both lines have "is". ...
-1
votes
2answers
51 views

Unix - Searching for every file with a certain string in it

I am searching for every file within a root directory and want to search every subdirectory as well. I have tried grep -r "message" * but I am not sure that this searches every subdirectory, any ...
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 ...
0
votes
2answers
239 views

Linux command to find all instances of a file pattern?

I'm looking for a way to scan a directory recursively and print out all instances of any file that ends ".qfx". Thus, for a given directory: somedir/ fizz.qfx buzz.qfx blah/ ...
3
votes
3answers
86 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 ...
1
vote
1answer
188 views

What is the difference between these two grep options?

I am writing a script. What is the difference between the following two lines? grep . || echo something and grep "^\." || echo something
-2
votes
1answer
72 views

Grep word in one file, and use that word to match in another file, adding the thing that follows the match

I want to grep several words in file1, and use each word to grep what follows after its match in file2. And then I want to add the string that followed the match to the word I used into file03, so ...
1
vote
1answer
123 views

Why does this grep filter not work as expected?

Preface: I've added alias airport="sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport" to my .zshrc. myuser:~/ $ airport prefs ...
0
votes
3answers
3k views

remove text from file

I want to remove some text from file1.txt. I put the text in the file tmp and do: grep -f tmp file.txt But it gives me only the difference. The question is how to remove the difference from ...
0
votes
1answer
2k views

Using Mac OS X terminal to copy a selection of folders to a new location, with merge behavior

I have a folder 'foo' that contains a lot of sub folders, e.g. foo |---20101 |---20102 |---20103 |---20111 |---20112 |---20113 There are way more than this, but hopefully it explains the ...
1
vote
0answers
99 views

Why is grep faster than ack [closed]

I have access to, but no admin rights on, one of our Ubuntu production server, so I had to install the single file version of ack. I did a trial run (ack vs grep). The results are not impressive and ...
0
votes
2answers
95 views

remove the zombie process from the output of ps

I m not looking to kill a zombie process. I m looking to avoid the display of zombie process in the ps command. Are there an option to add to ps command inorder to avoid displaying the zombie ...
0
votes
2answers
215 views

When I grep no particular file the terminal stops working

I'm learning how to use the shell. In playing around with some basic commands I encountered an issue. This is pretty basic stuff and I apologize if that upsets some folk. On my desktop there exists a ...
0
votes
2answers
50 views

How to grep a number following a keyword from a textfile?

How to grep the member id X01930 from the following file? Blah Blah ... Blah Blah Blah Blah ... Member ID: X01930 Blah Blah ... Blah ... Blah Blah ... Blah The string Member ID: is usually there, ...
1
vote
2answers
4k views

Dealing with whitespace in grep

I'm trying to figure out how to deal with whitespace in grep. How do I tell grep to find strings containing whitespace or tabs? The manual tells me nothing. \s seems to work for whitespace, and \S ...
0
votes
4answers
299 views

What are the advantages, if any of grep over egrep

I'm just learning about the grep family of programs, and it seems to me that egrep is strictly superior to grep - it can do everything that grep can do, but more. Am I wrong? Why not just use egrep ...
2
votes
3answers
303 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
2answers
122 views

how to pass a flag as an argument to grep

I'm trying to pass -- as an argument to grep because the file I'm interested in contains -- within its text, like so grep -- file.txt but I cannot because grep sees -- as a flag. How do I pass -- ...
1
vote
1answer
155 views

Generate CSV/TXT file from named zone file

I am in need of generating a csv/txt file from a zone file on a named DNS server. For examples I would like to generate a list of the hostname and IP from the zone file From this monkey A ...