tags:

views:

34

answers:

2

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
+6  A: 

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:

grep `date +'%y%m%d'` /var/log/mysqld.log | sed 's/^/computer /'

I also removed the 'g' modifier from your sed as it is completely unnecessary.

Mark Byers
A: 

Just one awk command

awk -vd=$(date +'%y%m%d') '$0~d{ print "computer "$0 }' /var/log/mysqld.log
ghostdog74