user2285103
user2285103

Reputation: 13

Solaris unix, c-shell, redirecting xargs executed command output

Have no choice about the c-shell. It's what we use here.

So I want to parse through current directory and all sub-directories looking for files of form *.utv and egrep each to look for a specific account number in the file.

I tried something like this:

egrep -l "ACCOUNT NO: +700 " `find . -name "*.utv" ` | more   

but got "Too many words from `` " message.

So using xargs because apparently I'm getting too many file names passed back to egrep command-line.

When I do this:

find . -name "*.utv" | xargs -n1 egrep -i -l '"ACCOUNT NO: +700 "' {} >&! /home/me/output.txt

"ps -ef" command shows:

% ps -ef | egrep -i "myuserid"  
myuserid 20791 22549   0 18:19:38 pts/20      0:00 find . -name *.utv  
myuserid 20792 22549   0 18:19:38 pts/20      0:00 xargs -n1 egrep -i -l "ACCOUNT NO: +700 "  
myuserid 22774 20792   1 18:21:13 pts/20      0:04 egrep -i -l "ACCOUNT NO: +700 " ./01/130104_reportfile.utv  
%

But I get no output in the "output.txt" file.

If I run the egrep part by hand in the same directory, I get a list of file names containing the account 700 string.

I'm sure it's just a matter of grouping, quoting proper, and/or having the redirect in the right place, but after quite a lot of trial-and-error (and searching here) I'm still not getting anywhere.

Any suggestions?

Upvotes: 0

Views: 492

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754550

You only need either single quotes or double quotes (but not both) around the search, as in your original command:

find . -name "*.utv" | xargs -n1 egrep -i -l "ACCOUNT NO: +700 " {} >&! /home/me/output.txt
find . -name "*.utv" | xargs -n1 egrep -i -l 'ACCOUNT NO: +700 ' {} >&! /home/me/output.txt

I'd also lose the -n1, the -i and the {} from the command line too. A trick to always get file names listed is to specify /dev/null as a name, but the -l also does the job:

find . -name "*.utv" | xargs egrep -l 'ACCOUNT NO: +700 ' >&! /home/me/output.txt

And you need to enlighten the powers that be that C shell is not good for programming. And you can always add exec /bin/bash -l to your .login script (or use /bin/ksh instead of /bin/bash). I simply wouldn't have any truck with "You cannot use a sane, civilized shell" rules.

Upvotes: 1

Related Questions