The first command does work as expected but not the second one. I want to add some text either at the beginning or the end.
# grep `date +'%y%m%d'` /var/log/mysqld.log
100101 10:56:00 mysqld started
100101 10:56:02 InnoDB: Started; log sequence number 1 2052750649
# sed 's/^/computer /g' < grep `date +'%y%m%d'` /var/log/mysqld.log
bash: grep: No such file or directory
# expected output
computer 100101 10:56:00 mysqld started
computer 100101 10:56:02 InnoDB: Started; log sequence number 1 2052750649
As you wrote it with input redirection, it looks for a file called
grep
in the current directory and tries to read its contents, not execute it. You need to use a pipe instead:I also removed the 'g' modifier from your sed as it is completely unnecessary.
Just one awk command