Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to do something like this:

cat 5.txt | xargs -0 openssl prime

but xargs is saying that argument list is too long


Edit:

cat 3.txt | xargs -n 1 openssl prime | wc -l

works, thanks

share|improve this question
    
hard to believe xargs would say "argument list too long" since you only give it three arguments. what makes you think xargs says this? –  stew Apr 6 '13 at 2:26
    
what is the format of 5.txt? –  stew Apr 6 '13 at 2:27
    
for "cat 5.txt | xargs openssl prime" works but only for 725 lines ,"file 5.txt 5.txt: ASCII text " –  asfsafsfsaf Apr 6 '13 at 2:29
    
can you give us more information, like the actual errors you get? –  stew Apr 6 '13 at 2:31
    
how many nulls exist in 5.txt? –  stew Apr 6 '13 at 2:36

2 Answers 2

You can try using xargs's -n:

Use at most max-args arguments per command line.

Also worth noting xargs can be made to

Print the command line on the standard error output before executing it.

with -t, which is rather useful for debuging.

share|improve this answer
    
@asfsafsfsaf, don't use -0, man –  poige Apr 6 '13 at 2:40
1  
@asfsafsfsaf, so what? 2946 * 4 = 11784, though I still don't see what that all wc -l exercise is about –  poige Apr 6 '13 at 2:51
    
-n 1 works, thanks –  asfsafsfsaf Apr 6 '13 at 2:59
    
@asfsafsfsaf, according to your previous data which you have deleted already (reasons unknown), xargs -n4 worked as well, you just couldn't get it. –  poige Apr 6 '13 at 3:18

The problem sounds like you should not be using -0, -0 is for when you have your arguments in the file separated by null characters instead of $IFS which is usually whitespace. If the file is formatted with one argument per line or with arguments separated by whitespace, omit the -0.

I'm also guessing that you don't intend it to run openssl prime arg1 arg2 arg3 arg4...." but instead runopenssl prime arg1then runopenssl prime arg2, thenopenssl prime arg3, etc, in which case, add the -1 switch as well, which is shorthand for-n 1`, if you really want to run one invocation of openssl per line of the file, you want:

xargs -1 openssl prime < 5.txt

or with the uuoc (useless use of cat)

cat 5.txt | xargs -1 openssl prime

on a non-gnu xargs which doesn't know the -1 option this would be:

xargs -n1 openssl prime < 5.txt
share|improve this answer
    
more like : openssl prime first line; openssl prime second line ... –  asfsafsfsaf Apr 6 '13 at 2:46
    
xargs -1 openssl prime < 5.txt xargs: wrong option -- '1' –  asfsafsfsaf Apr 6 '13 at 2:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.