Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

How can I use the output of one command - line-by-line - into another command? I know how to do this with the | pipe symbol, but this uses the entire output in one command. I would like to go line by line... I think I need to combine the | and xargs but not sure.

redis-cli keys \* | redis-cli get [key would go here]
share|improve this question

marked as duplicate by Gilles, jasonwryan, rahmu, slm, Anthon Dec 7 '13 at 4:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 5 down vote accepted

Use while to loop through each line:

redis-cli-keys \* | while read key; do redis-cli get "$key"; done
share|improve this answer
awesome thank you! is the term read always going to be in those types of commands? – d-_-b Dec 6 '13 at 2:35
read can be used in a lot of instances. For example, as a standalone to take input and assign to a variable (with a prompt): read -p "Enter a name: " name - the value entered will then be assigned to $name. – laebshade Dec 6 '13 at 2:37
Very cool, i'll look into that. thanks again - this worked! – d-_-b Dec 6 '13 at 2:40
read is also handy to assign words in a string to variables: x="1 2 3 4 5"; read a b c rest <<< "$x" – glenn jackman Dec 6 '13 at 2:47

The xargs answer would be:

redis-cli keys \* | xargs -L 1 redis-cli get
share|improve this answer
Thanks! This is very helpful! – d-_-b Dec 6 '13 at 23:21

Just for completeness here's the for loop variant:

$ for key in $(redis-cli-keys \*); do redis-cli get $key; done

NOTE: This works so long as the $keys do not contain spaces.

share|improve this answer
Awesome, thanks so much! – d-_-b Dec 6 '13 at 23:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.