Looping grep and xargs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping grep and xargs
# 1  
Old 07-18-2014
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
Code:
<appl.list xargs grep $1
 

where appl.list contains files (source programs) with the fields. This script is named YY
Code:
<fields.list xargs YY
 

appl.list contains file names like
Code:

ACCTMANT.cbl
ACCTPRT.cbl
ACCTPRTHS.cbl

while field.list looks like
Code:
FIELD-1
FIELD-2

When I run it, it finds only four references but when I run YY (by hand) field by field, it finds much more.

Any help would be appreciated. TIA
# 2  
Old 07-18-2014
If you're making multiple script files of 1 line each to get around a shell 'limitation' you've probably taken a wrong turn somewhere.

Your "YY" script is a forkbomb which would call itself recursively until you ran into process or memory limits or your computer hit swapdeath. You haven't shown how you're running it. Your data files are so short as to be useless for example purposes. So I think you really oversimplified things when posting it here.

But I think I figured out what you're trying to do... You're looking for .cbl files containing the strings FIELD-1, FIELD-2, etc -- yes?

Last edited by Corona688; 07-18-2014 at 12:21 PM..
# 3  
Old 07-18-2014
If so:

Code:
xargs grep -F -f field.list < app.list

# 4  
Old 07-18-2014
Thanks for looking at it.

When I tried it, it listed all lines in all programs instead of just those containing selected fields.
# 5  
Old 07-18-2014
Give me some example data to work with here. Something that will produce actual output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Xargs

Hello, I need some help with xargs $ ls aaa bbb ccc ddd$ ls | xargs -I{} ls -la {} -rw-rw-r--. 1 xxx xx 0 May 30 20:04 aaa -rw-rw-r--. 1 xxx xx 0 May 30 20:04 bbb -rw-rw-r--. 1 xxx xx 0 May 30 20:04 ccc -rw-rw-r--. 1 xxx xx 0 May 30 20:04 dddit's possible to have output like this with... (3 Replies)
Discussion started by: vikus
3 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

Help with xargs

hi Could any one please tell me the option using which we can run multiple commands using xargs I have list of files, I want to run dos2unix and chmod at one shot on them I tried google n searched man pages but couldnt really find the solution , please help right now im doing this ls... (4 Replies)
Discussion started by: sunilmenhdiratt
4 Replies

6. 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

7. 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

8. 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

9. Shell Programming and Scripting

why we use xargs..

hi , can anyone help me by saying why we use xargs.. is it acing like a place holder..? thanks, Krips. (3 Replies)
Discussion started by: kripssmart
3 Replies

10. Shell Programming and Scripting

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.. (5 Replies)
Discussion started by: freakygs
5 Replies
Login or Register to Ask a Question