views:

80

answers:

3
+1  Q: 

xargs not working

I want all the lines with assert_equal and without amazon.

I tried following but it is not working.

ack assert_equal | xargs ack -v amazon
+4  A: 

You don't need xargs:

ack assert_equal | ack -v amazon
Thomas
+1  A: 

There seem to be a couple of problems with your command. In the first part:

ack assert_equal

you do not provide a filename, so ack has nothing to process. In the second part:

xargs ack -v amazon

you are using xargs to provide the results from the initial ack as command-line arguments to the second ack, which is probably not what you intended. ack is already designed to accept data on standard input, so you do not need to use xargs at all.

Here is a statement that should work better:

ack assert_equal filename | ack -v amazon

or, if you are getting the output from another command, something like:

my_command | ack assert_equal | ack -v amazon

Mike Pelley
ack assert_equal shows tons of data. Thanks for replying.
Nadal
The `ack` available from betterthangrep.com (as mentioned by Dave Bacher above) will not return any data when run with a single argument (at least on my machine). Another `ack` program, the Kanji code converter, will output any text file provided as-is, but it does not take a -v argument so I'm guessing that's not it. Is there a third `ack` you might be using?
Mike Pelley
ack does not need a filename to search. It only needs a search pattern. It assumes it wants to search the entire tree down, starting with the current directory.
Andy Lester
A: 

ack is not a standard tool in *nix. since you have it, its ok. But if you are on a *nix system which doesn't have it, here's how you can do it

awk '/asser_equal/&&!/amazon/' file
ghostdog74