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

0
votes
4answers
348 views

Extracting specific line of text with grep for use in conky

I'm trying to extract the directory of the current playing song in Quodlibet for use in attempting to display album artwork in conky. In QL's current file ~/.quodlibet/current there is a line that ...
3
votes
4answers
679 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 ...
2
votes
2answers
695 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. ...
0
votes
3answers
99 views

How do I use grep to search subdirectories too?

How do I use grep to search subdirectories as well as the files in the current directory? Thanks.
0
votes
4answers
1k views

Why “ grep * ” not working?

On these days learning linux, I found something confued me: $ cat abcd line One line Two line Three $ cat abcd | grep * $ _ //nothing greped $ cat abcd | grep "" line One line ...
0
votes
1answer
59 views

Search files for regex and return which files contain matches

I searched everywhere but didn't find out how to return a file content that matches given words or a regex. cat /tmp/*.txt | grep "strings"
0
votes
3answers
175 views

linux, filter and format grep results

I have a script which outputs (2 results shown here) Tag: tag_453672 Path: /abc/hosts/server42/vol/tempfile.tmp Server host: server42 Region: unix Active: NO View tag ...
1
vote
1answer
717 views

How to grep file with prefix pattern?

How can I grep for lines of a file wich start with a certain string? For example, all lines with prefex 0x, where the file has the lines 0x002 0x003 abc Output should be 0x002 0x003
0
votes
4answers
412 views

Regular expression to find senders IP using grep or other languages

I have input file that contains: 19:04:01.631948 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [none], proto UDP (17), length 48) 181.173.82.61.1985 > 250.66.33.195.1985: HSRPv0-hello 20: ...
1
vote
3answers
171 views

Is it possible to open a file to a specific line number as formatted in grep -n results?

I often use grep with the -n option to list line numbers, e.g. $ grep -n xyz .* /ext1/acheong/foo/bar/a.cc:42: inline bool abc(int xyz); /ext1/acheong/foo/bar/a.cc:43: inline bool def(int xyz); ...
1
vote
1answer
409 views

grep with colored output returns several empty lines

I have strange issue with grep (2.12-2, debian testing). In some situations when I do something like this: grep -rni '."spacer">.' . grep return me several empty lines: If I add --color=none ...
3
votes
2answers
318 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 ...
1
vote
2answers
308 views

Is there a better way to do this command to find strings in a file excluding special characters?

Is there a better way to do this command to find strings in a file excluding special characters? Currently I'm doing: strings file.abc | grep -v \= | grep -v \] | grep -v \) | more I'd like to add ...
4
votes
2answers
2k views

How to grep a section of a file in bash shell

How can I "grep" the lines between an occurrence of some string1 and the (Nth) occurrence of some string2. e.g. if the file has line: A B C D E F G B C E Q I want to get the lines in bold (those ...
5
votes
1answer
10k views

Ubuntu Linux: find files between specific times?

I found an SO called using Find/Grep to search files between specific time of day Based on that and a Unix SE called Grep command to find files containing text string and move them I ended up with: ...
1
vote
1answer
850 views

How to Grep up to a certain character or String

I need to extract log data from many terrabytes worth of log files. The thing is, the data I need starts and ends with patterns I can identify, but the code between can be anything between 10 and 100+ ...
0
votes
1answer
2k views

Using find with -exec gzip and grep

I have a bunch of zipped up log files and I want to search them all for a string. I tried this but it's not working: find ./ -name "*.log.zip" -exec gzip -dc {} | grep ERROR \; It's giving me: ...
0
votes
3answers
115 views

Grep for This and NOT That in a File?

How can I grep for files in a directory structure that have this text addDesignControlChangeNotification but are missing this text removeDesignControlChangeNotification Thanks! Note: I mean the ...
1
vote
4answers
3k views

How to combine find and grep to recursively search for str or str2 in *.html and *.php files from /home/smith/sourcecode?

How can i combine find and grep to search for str1 or str2, recursively, in all *.html and *.php files starting from a directory named /home/smith/source? The output only needs to list files (with ...
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 ...
1
vote
3answers
1k views

How to grep long string across multiple lines, without knowing where the newline is

I want to search for a specific string across multiple lines in a file and get the line in which the match was found. However, my problem is, that the file contains one very long string, and not, ...
1
vote
2answers
93 views

Finding folders only

My harddrive is in a mess, so I decided to do a cleanup. As a part of this, I want to merge all folders containing music into one. What I want to do is, look for any *.mp3's and *.aac's on my drive ...
0
votes
2answers
72 views

Doubts in Grep to display file name along with content

Am using the following grep to match a particular pattern in grep. grep xyz abc.txt now while i run this command, if the pattern matched, am getting the line containing xyz Output: xyz is doing ...
1
vote
2answers
394 views

Vim hiding quickfix column / gutter

After running :vimgrep I'll get a column to the left that with indicators pointing at lines where things were found. After editing, how can I hide this quickfix column? Let me know if the question is ...
0
votes
2answers
1k views

Terminal highlight error when compiling with a make file

I have a simple make file and I want to highlite the word or line that contains "error:" to make it easier to see. I am SSH via Putty to the linux machine which may cause a problem but currently I ...
2
votes
1answer
688 views

How to ack-grep replace a string of multiple words

The following command replaces every occurence of the word from in any file of the current directory or its subdirectories with to: ack-grep -l --print0 --text from | xargs -0 -n 1 sed -i -e ...
0
votes
2answers
34 views

Bash: accessing another users documents

Using bash scripting I am trying to access another's users documents and search for a word in a file, how would I do this?
1
vote
1answer
43 views

What is the output of option 'n' for a grep on a device?

If I do this: grep -a -n 'test' /dev/sdb10 It will search on the device sdb10 at binary level for a string 'test'. I can see the output of 'n' option, but what does it represent? Is the device ...
0
votes
1answer
68 views

Why doesn't this xargs + grep combo work properly?

I have two files, team1.txt and team2.txt team1.txt =========== Alex Bob Charlie David team2.txt =========== Alex Charlie Benjamin Zed Noah I want to output the people who are in both team1 ...
2
votes
1answer
114 views

using grep -E with AND conditions (ex: (?=/fo)^(?=/mo))

I have little problem figuring out how to get a list of files that has: string "/fo" in it But does not have string "/mo" I'm trying to figure out that in folder with lot of text files... My ...
2
votes
2answers
67 views

Get everything on line but match with grep

I'm trying to get everything on the matched line excluding the match using grep. If I have #define VERSION 0.1 The command should echo 0.1 I saw this question, but I only want things on the ...
3
votes
1answer
213 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 ...
5
votes
3answers
290 views

Can bash consume the same fifo from two separate commands?

I have a huge data source that I'm filtering using some greps. Here's basically what I'm doing right now: #!/bin/bash param1='something' param2='another' param3='yep' echo $(avro-read /log/huge_data ...
1
vote
1answer
353 views

Subtract files from one another recursively between two similar directories

I'm trying to concoct a way to grab two (nearly identical) directories and show me the difference between all files in the two directories. Looking for two different things: 1- List all files ...
0
votes
1answer
168 views

Bash: Grep regular expression failing to work

When using grep like so: ps aux | grep 'processname' | awk '{print $2}' The PIDs of processes withprocessname is returned. When using this: ps aux | grep '^processname' | awk '{print $2}' I'm ...
0
votes
1answer
1k views

Grep issue (match two strings on same line)

Here I have some grep command which is not working correctly: cat file1.txt: apples Date: Sun, 24 Feb 2013 8:14:06 -0800 peaches melons cherry sky cloud green purple yellow cat file2.txt: apples ...
1
vote
2answers
158 views

Grep “out” matching and n subsequent lines

Consider a log file which looks like this: action A detail 1 detail 2 detail 3 action X detail 1 detail 2 action B detail 1 action X detail 1 detail 2 action C Lines with "action [ABC]" may have ...
0
votes
1answer
858 views

Search & Replace Using Grep and Sed Command

I want to remove the weird / special characters from the bunch of text files. Here i used the following command to remove the weird characters but it gives me the error. Command : 1) grep -lri -e ...
1
vote
3answers
1k views

Why doesn't piping grep output into xargs work with color?

I have a strange issue. My grep has colored output, and if I do something like this: grep -lr '80' /etc/apache2/sites-available/|xargs ls I got: ls: cannot access ...
1
vote
1answer
774 views

Extended regular expression new line

I seem to match two things using extended regular expressions: Newline. I have tried [ \n], [ \\n], both don't work Negative lookahead for string "timeout". I have tried (?!timeout) Can anyone ...
2
votes
3answers
8k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
0
votes
1answer
58 views

grep returning wrong messages in GNOME Desktop(Linux)

I need to search a particular string inside a folder structure. The File system contains multiple files, but i need to check only XML files. I searched and tried the commands for Linux Recursive ...
0
votes
1answer
121 views

How to stop grep matching in terminal escape sequences (or colorize to multiple colours)?

I've written a bunch of scripts to colorize matches, like this: $ echo abcdef | grepg c ab[green]c[/green]def $ echo abcdef | grepr e abcd[red]e[/red]f It also works when I chain it: $ echo abcef ...
2
votes
2answers
607 views

Conditional spaces in a regular expression?

Using grep, how would I do this in one command line? I have this so far grep '\$[0-9][0-9]\.[0-9][0-9]' money.txt with various strings in the text file, but I'm having issues satisfying some of my ...
0
votes
1answer
1k views

Linux Grep Multiple Log Files

I need to get output of any lines in all Apache access log files that have 25/Jan/2013:00:25 in them. My hosting company are being unhelpful in my investigation to track down what domain is allowing a ...
6
votes
2answers
606 views

Why is the grep/-r/--include combination slower than the find/-exec/grep combination?

From my understanding, the two following commands roughly accomplish the same thing: Command 1: find -name "filename.xml" -exec grep someString {} \; Command 2: grep -r --include=filename.xml ...
2
votes
1answer
338 views

How to output a partial or a number from a mataching in grep or ack

I have a text file demo.txt like below. This is a line with id (9) This (8) is another line with id (10) This is a line with id too 11 This line does nothing The file has some lines with id ...
7
votes
3answers
12k views

grep for “term” and exclude “another term”

I am trying to build a grep search that searches for a term but exludes lines which have a second term. I wanted to use multiple -e "pattern" options but that has not worked. Here is an example of a ...
2
votes
1answer
606 views

List running services

I am trying to get a list of the running services. I ran service --status-all It will return something like [ + ] acpid [ ? ] alsa-utils [ + ] apache2 [ + ] atd [ + ] avahi-daemon [ ? ] ...
0
votes
6answers
919 views

grep *.c not working

I have a list of ".c" (c files) in the current directory. I have to find all the .c files in the current directory. The command that can be used id ls *.c But, another way is to use grep. so if i ...