grep and xargs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep and xargs
# 1  
Old 11-22-2007
grep and xargs

guys... I wanna use xargs in such a way that i can use it in grepping the fileds..

something like this:

grep -p <xargs values> *

lemme know how to do this..
# 2  
Old 11-22-2007
What -p flag stands for, I can't find this in my version of grep. Can you post a sample or more info on what needs to happen ?
# 3  
Old 11-22-2007
Something like this:

Code:
command | xargs -i ksh -c ' grep -p "{}" *'

# 4  
Old 11-23-2007
it worked but the grep command ran for multiple times, ...

Last edited by freakygs; 11-23-2007 at 02:51 AM..
# 5  
Old 11-23-2007
grep -p <pattern> <file>

gives the paragraphic view of the <pattern> value in the <file>

Man page info. pasted below:
-p[Separator] Displays the entire paragraph containing matched lines. Paragraphs
are delimited by paragraph separators, as specified by the Separator parameter,
which are patterns in the same form as the search pattern. Lines containing the
paragraph separators are used only as separators; they are never included in the
output. The default paragraph separator is a blank line.


Lemme know if u need any example
# 6  
Old 11-23-2007
Quote:
Originally Posted by freakygs
it worked but the grep command ran for multiple times, ...
xargs can/will do that. Think of running something like 'find . -type f -exec grep foo {}\;' - that will exec 'grep' once for each file found. Now, running 'find . -type f | xargs grep foo' will minimize the number of time grep is called. It still may need to be called more than once, since there is a limit to the length of a command line, depending on your shell and architecture - for example, mine is roughly 32k. If I ran a huge search on a large source branch, I'd expect to search well over 32k files, so even in the best case scenario, xargs could not possibly build the "ideal" command line for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping grep and xargs

In a directory I have two lists, all files which could contain certain fields (they all share copied code) and a list of fields. My two scripts are <appl.list xargs grep $1 where appl.list contains files (source programs) with the fields. This script is named YY <fields.list xargs YY ... (4 Replies)
Discussion started by: wbport
4 Replies

2. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

3. Shell Programming and Scripting

Find common terms in two text file, xargs, grep

Hello, I'm interested in finding all occurrences of the terms in file1 in file2, which are both csv files. I can do this with a loop but I'm interested in knowing if I can also do it with the help of xargs and grep. What I have tried: cat file1 | xargs grep file2 The problem is that... (15 Replies)
Discussion started by: eon
15 Replies

4. UNIX for Dummies Questions & Answers

find . -name "*.*" | xargs grep "help"

Hi all, I am a unix noob. Need some basic help. I have tried using google, but not able to figure this out. Here are the scenarios: 1. How do I find a directory with a particular name, say "Merlin" in the entire file system? I tried : find / -type d -name "dir_name" The problem is I'm... (3 Replies)
Discussion started by: neil.k
3 Replies

5. Shell Programming and Scripting

File find | xargs grep for pattern file

Folks I've been struggling this with for far too liong now and need your help! I've been happily using grep for a search of a directory, to list the files which contain a string: find . -type f -mtime -5 -print | xargs grep -l 'invoiceID=\"12345\"' Now the list of 'invoiceID' I am... (4 Replies)
Discussion started by: daveaasmith
4 Replies

6. Shell Programming and Scripting

Xargs and

Hello there, Let me show you a simple example of what I am trying to achieve: 1) I have an input text file with some lines: 1 a 2 b 3 c 2) And I want to run a command with these lines as arguments (+ arbitrary extra arguments). For example: $ command "1 a" "2 b" "3 c" "bye" I... (7 Replies)
Discussion started by: tokland
7 Replies

7. Shell Programming and Scripting

Help in using xargs

Hi, I have a requirement to RCP the files from remote server to local server. Also the RCP has to run in parallel. However using 'xargs' retrives 2 file names during each loop. How do we restrict to only one file name using xargs and loop till remaining files. I use the below code for... (2 Replies)
Discussion started by: senthil3d
2 Replies

8. Shell Programming and Scripting

Using xargs

hi i just want to know that how do we use xargs command to find files which are greater than specified memory in a given directory (6 Replies)
Discussion started by: sumit the cool
6 Replies

9. UNIX for Dummies Questions & Answers

problem with grep in combination with xargs

Dear all, I have tried the following 2 lines xargs -t -i -exec grep -i -w {} file_1 >>test < file_2 cat -s file_2| xargs -t -i -exec grep -i -w {} file_1 >> test They were meant to search for the contents of file_2 in file_1 and write the respective lines of file_1 into file "test" .... (15 Replies)
Discussion started by: Bruno
15 Replies

10. UNIX for Dummies Questions & Answers

Help with xargs

Hi there, I am trying to move around 3000 files from one directory to another. The mv command is complaining from too many arguments. I tried to use the xargs command but with no luck. Could some body provide help? Regards (4 Replies)
Discussion started by: JimJim
4 Replies
Login or Register to Ask a Question