replace a text string

Posted by shantanuo on Stack Overflow See other posts from Stack Overflow or by shantanuo
Published on 2010-04-20T04:52:25Z Indexed on 2010/04/20 4:53 UTC
Read the original article Hit count: 329

Filed under:
|

I want to replace the date found at the end of the "datadir" line with the current date. For e.g. my my.cnf file looks like this...

# head /etc/my.cnf
[mysqld]

#mount -t tmpfs -o size=102m tmpfs /mnt
#datadir=/mnt
read-only
datadir=/mysqlApr5
#datadir=/mysqlApr2
#datadir=/mysqlMar16
#datadir=/mysqlFeb25a

Most of the lines are commented. I need to find the datadir line that is not commented and then replace the /mysqlApr4 with /mysqlApr20

datadir=/mysqlApr20

If it is possible I will like to comment the older datadir path.

#datadir=/mysqlApr5

I can output the current date as:

date '+%b%d'

But I want to concat it with the word "/mysql" and replace or comment the current datadir line.

© Stack Overflow or respective owner

Related posts about sed

Related posts about awk