For example, if I perform
ps aux | awk '{print $1}' | xargs -I {} echo {}
I want the shell to sleep for 1 second between each echo .
echo
How can I change the shell command?
You can use the following syntax:
ps aux | awk '{print $1}' | xargs -I % sh -c '{ echo %; sleep 1; }'
Be careful with spaces and semicolons. After each command, a semicolon is required between the brackets (even after the last).
Replace echo with some shell script named sleepecho containing
sleepecho
#!/bin/sh sleep 1 echo $*
If your awk supports it:
awk
ps aux | awk '{ system("sleep 1"); print $1 }' | xargs -I {} echo {}q
or skip awk and xargs in general
xargs
ps aux | while read -r user rest; echo $user sleep 1; done