4

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

asfsafsfsaf
  • 41
  • 1
  • 3

2 Answers2

4

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.

poige
  • 9,171
  • 2
  • 24
  • 50
  • @asfsafsfsaf, don't use `-0`, man – poige Apr 06 '13 at 02:40
  • 1
    @asfsafsfsaf, so what? 2946 * 4 = 11784, though I still don't see what that all `wc -l` exercise is about – poige Apr 06 '13 at 02:51
  • @asfsafsfsaf, according to your previous data which you have deleted already (reasons unknown), `xargs -n4` [worked as well](http://serverfault.com/questions/496720/xargs-too-long-argument-list/496723?noredirect=1#comment555709_496723), you just couldn't get it. – poige Apr 06 '13 at 03:18
2

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
stew
  • 9,263
  • 1
  • 28
  • 43