Well, you cannot hide ' inside ', and you have to do a 'command stdout to string' conversion $(...) or `...`. Think of echo as 'command line string to stdout' converter, and this is the opposite.
cp $(
ls -lrt | awk '
{print $6$7" "$9 }
' | grep `date +%b""%d` | awk '
{print $2}
' ) somewhere/new
Now, if you dislike nesting:
ls -lrt | awk '
{print $6$7" "$9 }
' | grep `date +%b""%d` | awk '
{print $2}
' | mv $( cat ) somewhere/new
Both of these are ugly if no files, so sometimes, put the list in an env. var.:
new=$(
ls -lrt | awk '
{print $6$7" "$9 }
' | grep `date +%b""%d` | awk '
{print $2}
'
)
if [ "$new" != "" ]
then
mv $new somewhere/new
fi
If the number of files is really big, like from a long find, then waiting for a complete list is an unconscionable delay, so you want to pipeline parallel more:
ls -lrt | awk '
{print $6$7" "$9 }
' | grep `date +%b""%d` | awk '
{print $2}
' | while read f
do
mv $f somewhere/new
done
but this lacks economy of scale on mv calls (nice for must-do-one-at-a-time commands), so use xargs to batch them up:
ls -lrt | awk '
{print $6$7" "$9 }
' | grep `date +%b""%d` | awk '
{print $2}
' | xargs -n101 echo | while read fs
do
mv $fs somewhere/new
done
xargs is 'pile args from this many stdin lines on the end of the supplied command and execute'. The number 101 is magic, in that you can argue that you got over 99% of any economy of scale while minimizing latency to first mv. Specifying the number to xargs with -n not only limits the delay to first mv, it also says no execute for 0 lines.
The grep pattern needs to be `date '+^%b''%d '` so it both matches the date only at beginning of line (^) not in the file name, and matches the space separator (May1 and not May19 ).