Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

:-) your own self. -- Larry Wall in <199709261754.KAA23761@wall.org>


devel / comp.lang.awk / Re: Edit line or add to end of [global] section of INI file

SubjectAuthor
* Edit line or add to end of [global] section of INI fileKen Teague
`- Re: Edit line or add to end of [global] section of INI fileKen Teague

1
Edit line or add to end of [global] section of INI file

<83498a66-4405-4aaf-a833-3bb1babb14een@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1613&group=comp.lang.awk#1613

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:6214:17c6:b0:656:170e:e884 with SMTP id cu6-20020a05621417c600b00656170ee884mr188763qvb.2.1696283275419;
Mon, 02 Oct 2023 14:47:55 -0700 (PDT)
X-Received: by 2002:a9d:740d:0:b0:6b9:620e:d6a7 with SMTP id
n13-20020a9d740d000000b006b9620ed6a7mr256108otk.1.1696283275205; Mon, 02 Oct
2023 14:47:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Mon, 2 Oct 2023 14:47:54 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=67.217.158.178; posting-account=-_F09woAAACpmJ2J3zbMUSuMEHFwR64a
NNTP-Posting-Host: 67.217.158.178
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <83498a66-4405-4aaf-a833-3bb1babb14een@googlegroups.com>
Subject: Edit line or add to end of [global] section of INI file
From: ken@onxinc.com (Ken Teague)
Injection-Date: Mon, 02 Oct 2023 21:47:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2633
 by: Ken Teague - Mon, 2 Oct 2023 21:47 UTC

I have an smb.conf file that is essentially of INI file format.

I'm trying to construct an awk 1-liner that will:
* check for the existence of the following line.
* If it doesn't exist, add it to the *end* of the [global] section.
* If it does exist, make sure it's as follows, or edit it to be as follows:

<tab>dfree command = /bin/dfree

I found this command that somewhat does what I need, but it's prepending a newline before adding the preferred line, so this:
[global]
....
log file = /var/log/samba/%m.log
guest account = guest

[samba]
path = /mount/samba
....

becomes this:
[global]
....
log file = /var/log/samba/%m.log
guest account = guest

dfree command = /bin/dfree
[samba]
path = /mount/samba
....

I'd like for it to look like this:
[global]
....
log file = /var/log/samba/%m.log
guest account = guest
dfree command = /bin/dfree

[samba]
path = /mount/samba
....

It also appears that it's not looking for and editing the line to match my preference (it's just appending):
[global]
....
log file = /var/log/samba/%m.log
guest account = guest
dfree command = /sbin/dfree

dfree command = /bin/dfree
[samba]
path = /mount/samba
....

This smb.conf file is part of a Linux distribution that is used on a hardware appliance. The contents and arrangement of items may change at any time, which is why I'm looking to do this the way I've described. I'm open to ideas if it can be done in a more efficient and reliable manner. Thanks in advance!

Re: Edit line or add to end of [global] section of INI file

<9039fded-e07f-4553-ae1f-700f633669f0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1614&group=comp.lang.awk#1614

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:622a:15c3:b0:412:8bb7:25a6 with SMTP id d3-20020a05622a15c300b004128bb725a6mr190666qty.4.1696283476544;
Mon, 02 Oct 2023 14:51:16 -0700 (PDT)
X-Received: by 2002:a05:6870:3a07:b0:1bf:51f7:b5b4 with SMTP id
du7-20020a0568703a0700b001bf51f7b5b4mr4571280oab.7.1696283476345; Mon, 02 Oct
2023 14:51:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Mon, 2 Oct 2023 14:51:15 -0700 (PDT)
In-Reply-To: <83498a66-4405-4aaf-a833-3bb1babb14een@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=67.217.158.178; posting-account=-_F09woAAACpmJ2J3zbMUSuMEHFwR64a
NNTP-Posting-Host: 67.217.158.178
References: <83498a66-4405-4aaf-a833-3bb1babb14een@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9039fded-e07f-4553-ae1f-700f633669f0n@googlegroups.com>
Subject: Re: Edit line or add to end of [global] section of INI file
From: ken@onxinc.com (Ken Teague)
Injection-Date: Mon, 02 Oct 2023 21:51:16 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3273
 by: Ken Teague - Mon, 2 Oct 2023 21:51 UTC

On Monday, October 2, 2023 at 4:47:56 PM UTC-5, Ken Teague wrote:
> I have an smb.conf file that is essentially of INI file format.
>
> I'm trying to construct an awk 1-liner that will:
> * check for the existence of the following line.
> * If it doesn't exist, add it to the *end* of the [global] section.
> * If it does exist, make sure it's as follows, or edit it to be as follows:
>
> <tab>dfree command = /bin/dfree
>
>
> I found this command that somewhat does what I need, but it's prepending a newline before adding the preferred line, so this:
> [global]
> ...
> log file = /var/log/samba/%m.log
> guest account = guest
>
> [samba]
> path = /mount/samba
> ...
>
> becomes this:
> [global]
> ...
> log file = /var/log/samba/%m.log
> guest account = guest
>
> dfree command = /bin/dfree
> [samba]
> path = /mount/samba
> ...
>
> I'd like for it to look like this:
> [global]
> ...
> log file = /var/log/samba/%m.log
> guest account = guest
> dfree command = /bin/dfree
>
> [samba]
> path = /mount/samba
> ...
>
> It also appears that it's not looking for and editing the line to match my preference (it's just appending):
> [global]
> ...
> log file = /var/log/samba/%m.log
> guest account = guest
> dfree command = /sbin/dfree
>
> dfree command = /bin/dfree
> [samba]
> path = /mount/samba
> ...
>
> This smb.conf file is part of a Linux distribution that is used on a hardware appliance. The contents and arrangement of items may change at any time, which is why I'm looking to do this the way I've described. I'm open to ideas if it can be done in a more efficient and reliable manner. Thanks in advance!

Sorry, I forgot to add what "this command" is:
awk -vT="dfree command = /bin/dfree" 'x&&$0~T{x=0}x&&/^ *\[[^]]+\]/{print "\t"T;x=0}/^ *\[global\]/{x++}1' /etc/samba/smb.conf

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor