m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: use m4 as a replacement for sed


From: Gerhard Lausser
Subject: AW: use m4 as a replacement for sed
Date: Wed, 13 May 2009 16:44:43 +0200

Hi,

somebody gave me a hint:

define service {
    register               0
    name                   `app_mssql_'DBSRV
    host_name              HOSTNAME
} 

Thanks anyway for reading my mail :-)

Gerhard

> -----Ursprüngliche Nachricht-----
> Von: address@hidden 
> [mailto:address@hidden 
> Im Auftrag von Gerhard Lausser
> Gesendet: Mittwoch, 13. Mai 2009 15:12
> An: address@hidden
> Betreff: use m4 as a replacement for sed
> 
> 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
> 
> 
> 
> 
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]