John Daniel
John Daniel

Reputation: 77

Add wc results as arguments in a pipe

I am experimenting with bash and I have the following:

grep 1000 data.txt  | wc | ./create_file

I am trying to find all records that include the number 1000, and use word count to calculate number of lines, word count and character count (default of wc).

Can I somehow add the calculations of wc as arguments for my custom script?

My script expects the 3 numbers produced by wc as arguments ($1, $2, $3)

I've also tried this but I can't seem to get the arguments individually:

grep 1000 data.txt | wc | xargs -I {} ./create_file {}

Thanks in advance

Upvotes: 0

Views: 902

Answers (1)

Barmar
Barmar

Reputation: 781726

Use command substitution:

./create_file $(grep 1000 data.txt | wc)

$(command) is replaced with the output of the command.

Upvotes: 2

Related Questions