word boundary in a awk command not working when printing a range of lines

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($)?

Matt Pedigo

Posted 2014-09-23T21:50:42.413

Reputation: 13

You are missing a /: '/\[\<CMI\>\]/{flag=1;next}/^$/{flag=0}flag' – NuTTyX – 2014-09-23T21:58:25.823

Yes. 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.657

samba 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.017

awk '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

Answers

0

I found the problem after thinking about the new line char in the file and how i got the test file. The test file that i am using was copied to the machine from a windows machine using Webmin via the samba configuration function and placing that out on a windows share in which several people had open the file for examination. When copying the file back to a linux machine, all newline chars were replaced by "^m" which was causing awk to total not find any newlines. Fix with fromdos command in the tofrodos package.

Found it here... https://stackoverflow.com/questions/811193/how-to-convert-the-m-linebreak-to-normal-linebreak-in-a-file-opened-in-vim

Matt Pedigo

Posted 2014-09-23T21:50:42.413

Reputation: 13