The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
xargs doubt shihabvk Shell Programming and Scripting 1 09-29-2005 10:38 AM
find | xargs cat asal_email Shell Programming and Scripting 4 03-17-2005 12:16 AM
Help with xargs JimJim UNIX for Dummies Questions & Answers 4 02-08-2005 07:08 PM
use of xargs command kishorebabu UNIX for Dummies Questions & Answers 5 10-30-2003 02:53 PM
xargs jpprial UNIX for Dummies Questions & Answers 4 09-17-2001 08:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2007
freakygs freakygs is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
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 (permalink)  
Old 11-22-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,322
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 (permalink)  
Old 11-22-2007
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Something like this:

Code:
command | xargs -i ksh -c ' grep -p "{}" *'
  #4 (permalink)  
Old 11-23-2007
freakygs freakygs is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
it worked but the grep command ran for multiple times, ...

Last edited by freakygs; 11-23-2007 at 02:51 AM..
  #5 (permalink)  
Old 11-23-2007
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Quote:
Originally Posted by freakygs View Post
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.
  #6 (permalink)  
Old 11-23-2007
freakygs freakygs is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0