4

I'm trying to use parallel and ack together to do some searching in parallel. However, ack seems to insist on using stdin if it finds itself in a pipe, even if you give it files to search:

$ echo hello > test.txt

$ ack hello test.txt
hello

$ echo test.txt | xargs ack hello
hello

$ echo test.txt | parallel ack hello {}

# ack thinks it should be searching stdin:
$ echo test.txt | parallel ack -f {}
-

# even though parallel is indeed passing test.txt:
$ echo test.txt | parallel --dry-run ack hello {}
ack hello test.txt

What do I need to do to get ack and parallel to play nicely?

mgalgs
  • 2,312
  • 4
  • 23
  • 33

3 Answers3

4

This happens on the current dev branch as well (9cc2407). The reason for this is that when standard input is a pipe, ack tries to be helpful and assumes you're trying to search that input stream. We've not seen this behavior before, so I've brought it up on the ack developers mailing list. In the meantime, you can use --nofilter to override ack's default behavior.

hoelzro
  • 56
  • 1
2

The problem is due to this line in ack:

$is_filter_mode = -p STDIN;

So these two situations are treated differently in ack:

cat file | ack ...
ack < file ...

The workaround for you seem to be to add a cat:

echo test.txt | parallel cat {} \| ack hello

This works in ack 2.12.

Ole Tange
  • 4,529
  • 2
  • 34
  • 51
0

I think ack is sick: Its behaviour is not deterministic, but it produces different output from time to time. Here I run the same command 100 times. 54 of them give "hello: No such file or directory". Note ack is being run by bash not by GNU Parallel.

$ seq 100 | parallel -N0 echo ack hello test.txt > test.sh
$ bash test.sh 2>&1 | sort | uniq -c
 54 hello: No such file or directory
100 hi

I can reproduce this behaviour when running this by hand 100 times:

$ ack hello test.txt
<<Sometimes:>> hello: No such file or directory
hi
Ole Tange
  • 4,529
  • 2
  • 34
  • 51