1
vote
2answers
219 views

batch find/replace using sed or awk

In every file with filename matching pattern1 I want to search for lines which start with pattern2, and add some string in a new line above those matched lines. As a simple example suppose I'm ...
1
vote
2answers
66 views

How do I search for a string in a group of files when some of those files contain spaces?

I'm running Mac 10.7.5. In a terminal, I'll use this command for finding files with strings find src/main -name "*" | xargs grep -i 'mystring' However when the files contain spaces, I'll get ...
2
votes
2answers
77 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") ...
3
votes
1answer
3k 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
59 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 ...
1
vote
3answers
710 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 ...
0
votes
4answers
144 views

how to do grep in the man command of linux using xargs?

I want to grep into a manual of a particular command say man grep |grep 'insensitive'. One of friends told me that It can be done using xargs but I cant seem figure out how. I want to do it using ...
3
votes
1answer
737 views

grep, xargs, sed to clean up PHP eval hack

I'm attempting to use the commands found on http://devilsworkshop.org/tutorial/remove-evalbase64decode-malicious-code-grep-sed-commands-files-linux-server/55587/ to clean up a PHP eval based hack on a ...
0
votes
1answer
73 views

How do I grep for foo && !bar?

I want to output all the lines in my source code which contain the string foo but don't contain the string bar. I tried this: find . -name "*.[hc]pp" | xargs grep -n foo | grep -x bar However ...
1
vote
2answers
992 views

Remove all except one file and directory at path

I need to remove all the files in a directory except for one file and one folder. Up to the grep I can output the correct list of items I want to remove but when i add xags, nothing is deleted. this ...
1
vote
2answers
166 views

Can I simulate ack by using grep with the right combination of options?

I have ack-grep installed on my local machine, and find it indispensable for quickly 'acking' through a codebase when debugging. However, on my cheap shared hosting, there is no ack-grep. One of the ...
3
votes
3answers
2k views

How can I grep in source files for some text?

At the moment I'm using two commands, I'm sure there must be a better way... wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset wim@wim-acer:~/ffmpeg$ find . -name ...
1
vote
2answers
2k views

How to feed grep output into scp?

I have a file where each line is a file name. Content of the file: file1 file2 file3 ... I then run a grep command to get a subset of the list of the file names. How do I feed the output of the ...
4
votes
4answers
4k views

What is a Linux command to find files containing some strings but not another?

I'm trying to search a lot of XML files for certain strings but not other strings, and I'm having trouble putting a command together to do it. I only want it to list the file names that match the ...
0
votes
1answer
3k views

How to construct a grep command with a variable argument in bash?

I'm trying to do something like this in bash: grep ( date | awk '{print "2006-" $6}' ) /some/file/here But that syntax is incorrect. The goal is to grep /some/file/here for the pattern 2006-2011 ...
5
votes
2answers
3k views

Grep exits abnormally with code 123 when running rgrep on emacs

Greetings fellow Emacsers I'm running GNU Emacs 23.1.1 on "Ubuntu 10.04.1 LTS" and any search I perform using the built-in M-x rgrep on the standard Linux kernel source code (vanilla) ends ...
2
votes
3answers
2k views

find . -exec grep -l 'string' {} \; -print 2>/dev/null

it lists all files in "." that contain the string "string" but don't show dirs with permission denied. What would it be the equivalent of that but squeezing xargs in between?
1
vote
4answers
155 views

printing matching lines when greping all files in a directory

I'm searching within Java files for some occurrence of a phrase: find . -name '*.java' | xargs grep -l 'string' How do I change this command to print to the shell all of the lines which contain a ...