grep is a command-line tool for searching text patterns in files

learn more… | top users | synonyms

1
vote
4answers
4k views

How to display line number while doing grep on a file

How to display line number while doing grep on a file. For example: grep CONFIG_PM_ADVANCED_DEBUG /boot/config-`uname -r
2
votes
3answers
121 views

Finding out how many programs I have not installed from a list with grep/awk in archlinux

I want to see how many packages from a list are not installed. I use archlinux, so I use pacman -Q to determine if a package is installed. If it is not installed, it returns a message like: "error: ...
4
votes
1answer
655 views

grep --color adds ANSI code ESC[K - This can change displayed text

Why does grep add ANSI code \e[K to its colored output? I can't see the point of it, but obviously the developers can. It is an ANSI/VT100 Terminal code which is used to "Clear line from current ...
4
votes
1answer
1k views

Bash, remove lines containing string with grep

This is currently deleting the whole contents of the file in question: #!/bin/bash rpc_port="9201"; dir="/etc/apache2/ports.conf" cat $dir | grep -v "Listen $rpc_port" > $dir The file contents: ...
8
votes
2answers
806 views

How do I take a list and remove it from a file?

I have a long list of domain names that I need to remove from /etc/remotedomains. They're probably not in any particular order in the file. Each domain is on one line. How could I iterate through the ...
4
votes
3answers
1k views

Why piping find and grep returns nothing?

I'm trying to have grep search inside specified files that are returned by find: find . -type d -name 'mydir*' -exec find '{}' -name '*.java' \; | grep 'MyClass' This doesn't work. Meanwhile, ...
6
votes
3answers
8k views

Pipe find into grep -v

I'm trying to find all files that are of a certain type and do not contain a certain string. I am trying to go about it by piping find to grep -v example: find -type f -name '*.java' | xargs grep -v ...
6
votes
1answer
502 views

Peculiar piping grep/head behavior

I'm helping the netadmin here with a perl regex to automate operating on some snapshots from our SAN and our scripts does stuff like this: varinit1=$(iscsiadm -m session | grep rbmsdata1 | head -n1 | ...
0
votes
1answer
260 views

PHP file recursive change array key on find [closed]

I used PHP array $lang['module']['1'] = 'Title'; $lang['module']['2'] = 'Title2'; $lang['value'] = 'text123'; how i can use replace in terminal Key Value to CASE UPPER ? $lang['VALUE'] ...
8
votes
4answers
5k views

Finding a substring in files across subdirectories with a single built-in command?

In Windows, if I wanted to find a string across all files in all subdirectories, I would do something like findstr /C:"the string" /S *.h However, in Linux (say, Ubuntu) I have found no other way ...
2
votes
1answer
486 views

How can I use unix tools with Cyrillic text?

I recently started processing Cyrillic text, and it's been really difficult. I couldn't get my Python scripts to work with it at all. And I tried. PHP worked well, but I don't know PHP. I just ...
2
votes
2answers
1k views

How to do a regex search in a UTF-16LE file while in a UTF-8 locale?

EDIT: Due to a comment Warren Young made, it made me realize that I was not clear on one quite relevant point. My search string is already in UTF-16LE order (not in Unicode Codepoint order, which is ...
4
votes
5answers
591 views

grep second time faster

Suppose I do a time consuming recursive grep search. After seeing the results I want a different output; for example I want to add the option -C 3 for 3 context lines. I can do the whole search again ...
2
votes
3answers
1k views

Grepping several lines from Nmap output

I apologize in advance as this is a simple question. So I'm attempting to scan a Class C to identify all mail servers by IP. The vast majority of IPs aren't mail servers. I'm trying to filter out the ...
1
vote
2answers
625 views

Is there any other way to use tail -f for grep -q && operation?

I found this solution: http://stackoverflow.com/questions/7178888/grep-q-not-exiting-with-tail-f but is there any other possible? UPD: I want to do tail -f | grep -q something && echo ...
1
vote
4answers
1k views

Grepping over a huge file performance

I have FILE_A which has over 300K lines and FILE_B which has over 30M lines. I created a bash script that greps each line in FILE_A over in FILE_B and writes the result of the grep to a new file. ...
9
votes
2answers
293 views

“Grep breaks, causing the boot process to hang forever”

Question within a question (from the Debian wiki): Should I use sid on my desktop? If you think you can handle a broken Debian system, sure. Do you know what to do if libpam0g breaks, ...
0
votes
1answer
1k views

last modified with grep

I'd like to make a list to stdout of the files modified in the last two hours in the . directory using grep. It has to be automatic (can't ask user what time is it or similar stuff) and I have to use ...
5
votes
2answers
3k views

Where does grep -r search by default?

I found if I search using grep without specifying a path, like grep -r 'mytext' it takes infinitely long. Meanwhile if I search with path specified grep -r 'mytext' . it instantly finds what I need. ...
1
vote
2answers
540 views

Weird zsh grep -P behaviour

I connect to server with PuTTY from Windows. I have a long yet not touched (I suppose) by hands of local admin config: $ cat /opt/jira/.subversion/config ... ### must be enabled, which is ...
2
votes
3answers
385 views

“Grep-ing” from A to B in hexdump's output

Here is the situation: I have to find in the output from an hexdump the bytes between a string A and a string B. The structure of the hexdump is something like: -random bytes -A + useful bytes + B ...
2
votes
4answers
7k views

How to find the total number of occurrences of text and files with find command

I am trying to run the find command to find the total number of occurrences of a particular text string and also the number of files which has this text string. What I have right now is this command. ...
1
vote
2answers
386 views

How do I generate a list of the characters occurring before a certain character only in lines that contain another certain character using regex?

I know that's super confusing (total noob-sorry!). To clarify, I have a text file that looks like this: 407-OL? 408-2-OL? 408-OL? 418-het? 420-1 and 2- OL? 429-2-left unscored? 430-2-left both ...
3
votes
2answers
173 views

Is there a global grep.conf in Unix/Linux?

I would like to make a utility that always enables the --color argument for the grep command in any distribution. Is there a way to do this or do I have to search for a way for each distribution?
5
votes
3answers
2k views

Grep_color on mac

I am trying to get my regex highlighted on mac using terminal. I have put this is my .profile: export GREP_COLOR='1;30;40' Nothing changes, so I added the same to my bash.profile still nothing, ...
1
vote
2answers
3k views

Why does adding a colon break this grep pattern?

I executed a search with grep, but it doesn't work like I expected it to. I have the following lines in a file: blacklists/redirector/domains:needyoutube.com ...
2
votes
1answer
219 views

Is it a good idea to supplement shell script with perl purely for use of regex?

I'm looking for a simple way to utilize regex in a UNIX shell script where not every system will have perl extensions built into grep. What is really helpful about perl regex here is back/forward ...
-2
votes
2answers
803 views

To display the selected part in line of text file [closed]

I have the following in a text file: 0400903071220312 20120322 20:21 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS 182644 ...
1
vote
1answer
707 views

How to grep for a single quote?

I am grepping through some VB source files. I use the following query - grep -nr "GlobalCommArea\s*=\s*.*\.Transaction" . Some of the lines, however, are commented and begin with a single ...
0
votes
2answers
453 views

Removing a long string from php files - using grep and sed?

I have encountered some malware on my Linux server, and am trying to remove it from many php files. I've tried endlessly with grep | sed and grep | tr and couldn't even erase a simple text string, ...
9
votes
3answers
4k views

How to perform GREP on FTP?

I tried searching for similar command in ncftp (actually this is the only terminal ftp client I used) and I didn't find it. What's the way (if possible at all) to use grep command on remote server, ...
3
votes
3answers
688 views

Longest common substring using grep

I have a huge text file called dictionary.txt with entries like ABC_SEQ_NUM This represents.... ABC_RANK This represents.... ABC_BSC_ID This represents... PQR_TA_DATE_AF This ...
0
votes
2answers
3k views

How to search all subdirectories and their subdirectories for the occurence of a word using grep? [duplicate]

Possible Duplicate: Searching for string in files Suppose I have a directory called Home and it is my current directory. And in this home directory I have many other directories ...
2
votes
3answers
3k views

How to combine two grep statements and display their results together?

Suppose I do grep "MyVariable = False" FormA.frm ... result1 grep "MyVariable = True" FormA.frm ... result2 How to write the grep command so that I can say something like grep ...
4
votes
1answer
158 views

How can I act on the results of the “locate” command?

I'm trying to find where check_dns is defined in nagios' commands.cfg file, although there are quite a few files. I know I could run something like find / -name "command.cfg" -exec grep check_dns {} ...
2
votes
2answers
1k views

Recursively replace string in files

I want to replace the backslash in the string page_path\example_filename.txt with a forward slash. I also want to be able to run this on a large file system and have it recursively search all ...
1
vote
1answer
165 views

Listing specific lines in listed files

Find all files in /tmp that are ordinary files and print the lines that end with Programming. For this problem I know how to list all files in /tmp. What I do not know how to do is whether to use ...
1
vote
1answer
587 views

What does this egrep command do?

What does this egrep command do? egrep '[^A-M][0-9]+' /etc/passwd So far I think it searches for any file in /etc/passwd that starts with A-M and includes the number(s) 0-9. Is that right?
0
votes
2answers
234 views

why does grep -A n give more lines than n?

I am verifying UID/GID for certain users using the dscacheutil command. Using grep with -A flag gives me what I need but the number of lines doesn't make sense. Output below: Edit8:~ edit08$ ...
5
votes
1answer
2k views

How to use grep/ack with files in arbitrary encoding?

On my Linux desktop I have a UTF-8 locale. When I try to search some KOI8-R encoded files with grep (ack), it fails. If I manually encode the pattern into KOI8-R and pass that as an argument, it ...
0
votes
2answers
492 views

ls outputs multiple columns even if piped to grep with grml's zsh config

I just decided to give zsh a go against Bash and came across some unhandy behaviour about which I couldn't find anything on the net: If you do a ls | grep foo in Bash, the ls only contains one file ...
5
votes
2answers
985 views

How to grep on source code without catching comments

I search a way to grep on source code without having sometimes false-positive because of comments. For instance if I search on foo on this .c source code : /* * foo has changed [...] and is now a ...
3
votes
2answers
10k views

using xargs to grep multiple patterns

I have a file that has terms I want to grep for, with each term being one line in the file. I was thinking I could do this with xargs. What I'm able to glean from examples from the man page like this ...
3
votes
3answers
802 views

Extracting text from a text file in bash

I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file. For ...
1
vote
1answer
2k views

How to grep a text recursively on BusyBox 1.0?

How can I find a file containing a certain string on a BusyBox 1.0, if grep -r does not work?
2
votes
3answers
206 views

Finding a number of occurrences of a certain character in tcsh

I am trying to find the number of certain types of files that have a '_' in the filename. I'm a massive beginner so my syntax looks like this at the moment; foreach txt ( 'ls *.txt') set n=0 if(grep ...
4
votes
2answers
5k views

What is the python equivalent of grep -v?

I like grep -v. I use it all the time. But I am also doing some text processing in python, and there is one crucial thing that I lack. Usually, I use grep -v to take extraneous stuff out of text. ...
6
votes
1answer
5k views

grep for words of no more than a certain length

I'm looking for a way to grep things like: i log for E M, i 1 f x i 0, I xi 1, 3 1,. simply based on number of characters. Nothing in that hypothetical output is longer than three characters. This ...
3
votes
2answers
4k views

Grep: search and replace full line

The command grep "foo" myfile.txt prints all matching lines in my file. Now I want to replace the full line with another string. How can I do that?
3
votes
2answers
700 views

Concatenate specific files into one single file

In a folder containing X files, I need to concatenate Y files (where X > Y) together into a single text file. I have the filenames (of Y files) that I need to concatenate. Can anyone please help me ...