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
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
73 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
127 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
4k 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
103 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 ...
1
vote
2answers
102 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
236 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
51 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
5k 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 ...
1
vote
4answers
328 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
315 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
124 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
169 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 ...
-1
votes
2answers
2k views

Why escaped single quote doesn't work in grep?

I am trying to match a string: * * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw with: crontab -l | grep '^[^#].*/usr/local/bin/growlnotify.*\-n \'myApp\'.*$' ...
1
vote
2answers
342 views

netcat output into separate files using string delimiters

I want netcat to pipe the output of a tcp/ip connection to commands that examine the output and split it into distinct files separated by the strings "msg" and "/msg" from the output, something like ...
3
votes
2answers
5k views

Recursively list full absolute path of files with permissions in Linux

I have done a bit of searching online, and I am trying to find a way to recursively list all files with their absolute path and with their permissions. I want to do this so that I can grep out what I ...
0
votes
1answer
302 views

The outputs of ps and top do not match

I have a situation where I have a process, say script.pl (here it is), which seems to stick around in the output to ps auxw | grep script.pl, sometimes when load is heavy it sticks around for several ...
0
votes
2answers
505 views

How to grep all logged in users?

How to grep all the logged in users from a user list in Linux (Ubuntu) ? So far I got to: cat /etc/passwd | grep "/home" | cut -d: -f1
4
votes
1answer
4k views

Using grep to remove lines from a file which contain a string from another file

I have a file containing words (one per line) such as Dog Fish Cat Shoes I have a secondary file in CSV format such as 1,shoes,red 2,apple,black 3,fog,blue I would like to use grep with ...
0
votes
4answers
331 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 ...
2
votes
4answers
539 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
544 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
92 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
925 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
56 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
158 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
554 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
343 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
142 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
354 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
294 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
286 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
1k 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
7k 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
704 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
1k 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
2k 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
64 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
89 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
67 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
323 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
965 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
528 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
33 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
40 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
64 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
104 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 ...