[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
use m4 as a replacement for sed
From: |
Gerhard Lausser |
Subject: |
use m4 as a replacement for sed |
Date: |
Wed, 13 May 2009 15:11:48 +0200 |
Hi List,
i want to use m4 to replace certain substrings in a text file.
My file looks like this (a Nagios configuration file):
define service {
register 0
name app_mssql_DBSRV
host_name HOSTNAME
}
What i want to do is to replace DBSRV and HOSTNAME which is simple with sed:
$ cat sample.cfg | sed -e 's/DBSRV/CMQS/g' -e 's/HOSTNAME/dbsrv11/g'
define service {
register 0
name app_mssql_CMQS
host_name dbsrv11
}
Alas, i like the definition of macros on the command line with m4. I think
this would be easier to script.
$ cat sample.cfg | m4 -DDBSRV=CMQS -DHOSTNAME=dbsrv11
define service {
register 0
name app_mssql_DBSRV
host_name dbsrv11
}
Unfortunately i found no way to make the DBSRV-substring in app_mssql_DBSRV
be recognized as a macro.
I played with "app_mssql_(DBSRV)" and it worked, but the delimiters appeared
in the output so i had to add a sed-command which replaced (.*) with .* .The
other thing is...i don't want to add too much extra code to the input file.
What i understand is, DBSRV as a substring is not a macro and will me
ignored by m4.
Maybe it's impossible at all but maybe someone knows a simple trick how to
detect a macro name embedded in another string.
Cheers,
Gerhard
- use m4 as a replacement for sed,
Gerhard Lausser <=