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

1
vote
1answer
235 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
237 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
228 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
556 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 ...
3
votes
1answer
2k 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
319 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
799 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
105 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 ...
0
votes
4answers
1k 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 ...
2
votes
2answers
52 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
795 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
81 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
54 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
224 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
621 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 ...
1
vote
1answer
243 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
29 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
38 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
58 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
83 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
47 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
144 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
180 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
172 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
118 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
311 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
97 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
500 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
611 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
278 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 ...
0
votes
3answers
1k 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
45 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
80 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
349 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
597 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
489 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
133 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
4k 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
228 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
548 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 ...
3
votes
2answers
208 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
1
vote
3answers
2k views

How to grep logfile via SSH on multiple servers?

Sometime, I need to find out specific log content(such as api call) from log files, those log files exists in several Linux servers. I have to use SSH to login every server and use grep searching the ...
2
votes
1answer
290 views

What's *nix terminal command to find and remove found files?

I have a malware on my server. So I've figured out how to find all that malicious files grep -r --include*.php "Some String from files" . That seems work fine! but how to delete them? I've tried ...
3
votes
5answers
2k views

grep count multiple occurrences

Is it possible to do a grep count of multiple occurrences in a file in one single command? For example: $ cat > file blah alfa beta blah blah blahgamma gamma I can do: grep -c 'alfa' file 1 ...
2
votes
2answers
911 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> ...
0
votes
1answer
214 views

Open file directly after grep

I'm getting an issue on piping in linux, ls | grep feedback I have an alias for xdg-open which is open, how can do to make the filename from grep goes directly to open this is not working ls | ...
0
votes
4answers
111 views

Simple script parsing text, what is wrong here?

I'm a big user of https://www.grc.com/passwords.htm to get strong passwords. However, having to go to the site and manually copy the password every time gets old fast, so I decided to do a little ...
2
votes
2answers
83 views

Maintain text colors when wrapping command in bash script

So I've made a small script to search through my project for a word: #!/bin/bash grep -n $1 js/*/**.js grep -n $1 js/*.js When running these commands in the command line I will get some nice syntax ...
7
votes
2answers
1k views

Edit first line of large text file

I have a huge text file, far too big for the whole thing to be paged into memory. All I need to do with this text file is edit the first line (its a CSV file and I need to alter the titles). Is there ...
2
votes
1answer
147 views

What does this grep command actually do?

I'm trying to get a hang of grep. I've got the following command from a GeekLet script that someone made for getting the weather info off some website: curl -s ...