0
I am attempting to parse samba .conf file for a specific share section...
[CMI] oplocks = no wide links = no writeable = yes delete readonly = yes path = /LOCALSITE/CMI comment = CMI Data write list = @cbishare valid users = @cbishare create mode = 775 directory mode = 775
Here is the code I am using to get the specific section using awk...
awk '/\[\<CMI\>\]/{flag=1;next}/^$/{flag=0}flag' /etc/samba/smb.conf
When I run this awk command without the code to get multiple lines {flag=1;next}/^${flag=0}flag
I get just '[CMI]'.
Is there something wrong with my code to get all lines up to a newline char($)?
You are missing a
/
:'/\[\<CMI\>\]/{flag=1;next}/^$/{flag=0}flag'
– NuTTyX – 2014-09-23T21:58:25.823Yes. Just the CMI section which should consist of all lines below "[CMI]" to the next empty/newline char($). this is to be used in a script on a stripped down version of Puppy linux and to keep it very small I am not allowed to install additional packages/libraries. – Matt Pedigo – 2014-09-23T22:00:53.877
You could also divide record by double new-line and awk simply by the title:
awk 'BEGIN {RS="\n\n"} /\[CMI\]/ {print}' /etc/samba/smb.conf
– NuTTyX – 2014-09-23T22:04:02.657samba conf file(smb.conf) has to use specific format where the sections are seperated by a new line. Altering the format may cause unwanted results for required samba shares. Sorry but not an option but thanks. – Matt Pedigo – 2014-09-23T22:10:20.637
Didn't get your question right. You needed the "extra" new-line char then. Using flags:
awk '/\[\<CMI\>\]/{flag=1}/^$/{if (flag) print;flag=0}flag' /etc/samba/smb.conf
, using RS:awk 'BEGIN {RS="\n\n";ORS="\n\n"} /\[CMI\]/ {print}' /etc/samba/smb.conf
– NuTTyX – 2014-09-23T22:18:21.017awk 'BEGIN {RS="\n\n";ORS="\n\n"} /[CMI]/ {print}' /etc/samba/smb.conf returns multiple sections because of the missing "<" ">" for exact matches for CMI in the pattern – Matt Pedigo – 2014-09-23T22:34:46.523
I need to edit the question to better reflect the issue – Matt Pedigo – 2014-09-23T22:41:18.007