sort redis output from terminal for use with comm command

163 Views Asked by At

I'd like to use unix's comm command to compare different results from redis.

Redis outputs will be strings separated by new lines, for example:

# redis-cli smembers set_1
1) "term 1"
2) "term 2"
3) "term 3"

#redis-cli smembers set_2
1) "term 2"
2) "term 4"

so I was trying something like:

comm -12 <(sort redis-cli smembers "set_1") <(sort redis-cli smembers "set_2")

But there's clearly something wrong here, I think this sort command only works with actual files, not outputs.

So is it possible to use comm to sort the output of redis?

1

There are 1 best solutions below

0
On BEST ANSWER

But there's clearly something wrong here

Yes, sort would expect filenames as arguments (in addition to sort options).

You can say:

comm -12 <(redis-cli smembers "set_1" | sort) <(redis-cli smembers "set_2" | sort)

Note that depending upon the desired sorting for the output of redis-cli ..., you might want to pass arguments to sort. Options such as -k, -s, -t might help.