Build Stats out of output

Hi,

I am required to build up a stats out of returned output. Something like given below. I would like first string in first column with a heading, and so on.

Is there any way I could do it, while adding something after the command, or any other way.

bash-2.05$ grep -i "nsslapd-accesslog*" /apps/EIS/dir/slapd-*/config/dse.ldif
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif:nsslapd-accesslog-logging-enabled: on
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif:nsslapd-accesslog: /export/apps/EIS/dir/slapd-ED-DataDir/logs/access
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif:nsslapd-accesslog-maxlogsperdir: 10
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif:nsslapd-accesslog-maxlogsize: 100
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif:nsslapd-accesslog-logrotationtime: 1
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif:nsslapd-accesslog-logrotationtimeunit: day
/apps/EIS/dir/slapd-ED-MV/config/dse.ldif:nsslapd-accesslog-logging-enabled: on
 Path	Attribute	Value
/apps/EIS/dir/slapd-ED-DataDir/config/dse.ldif	nsslapd-accesslog-logging-enabled	on

Thanks, John

something along these lines...
play with the 'fmt' formating to line up your headers:

nawk -F: 'BEGIN{fmt="%-50s%-40s%-10s\n";printf(fmt,"Path","Attribute","Value")}tolower($2)~"nsslapd-accesslog*" {printf(fmt,$1,$2,$3)}'  /apps/EIS/dir/slapd-*/config/dse.ldif

It is just giving me the header, no output.

bash-2.05$ nawk -F: 'BEGIN{fmt="%-50s%-40s%-10s\n"; printf(fmt,"Path","Attribute","Value")}tolower($2)~"nsslapd-accesslog*" {printf(fmt,$1,$2,$3)}' /apps/EIS/dir/slapd-ED/config/dse.ldif
Path                                              Attribute                               Value     

---------- Post updated at 08:50 AM ---------- Previous update was at 08:49 AM ----------

The above one was specific to one folder, this is the one which you suggested.

bash-2.05$ nawk -F: 'BEGIN{fmt="%-50s%-40s%-10s\n"; printf(fmt,"Path","Attribute","Value")}tolower($2)~"nsslapd-accesslog*" {printf(fmt,$1,$2,$3)}' /apps/EIS/dir/slapd-ED/config/dse.ldif
Path                                              Attribute                               Value     

There're no 'folders' in *NIX - only directories.

  1. You have to specify files as input to awk - not a directory
  2. Do the files specified have 'nsslapd-accesslog' as part of the second field?

yes, dse.ldif file is indeed a file, and it contains the search string 'nsslapd-accesslog'

please post a sample set of records from the file.

Here is the content that i want pull up :

nsslapd-accesslog-logging-enabled: on
nsslapd-accesslog: /export/apps/EIS/dir/slapd-ED/logs/access
nsslapd-accesslog-maxlogsperdir: 10
nsslapd-accesslog-maxlogsize: 100
nsslapd-accesslog-logrotationtime: 1
nsslapd-accesslog-logrotationtimeunit: day
  1. I've asked for the records/lines from the ORIGINAL file - not what the report should look like.
  2. If this is the desired report, it's not what you were after originaly

Still need a set of records from the ORIGINAL file.

That is record from original file, and not the output.

Oh, I see - your original had the 'grep' incorporated into it so it added a field.
Here it's:

nawk -F: 'BEGIN{fmt="%-50s%-40s%-10s\n";printf(fmt,"Path","Attribute","Value")}tolower($1)~"nsslapd-accesslog*" {printf(fmt,FILENAME,$1,$2)}'  /apps/EIS/dir/slapd-ED/config/dse.ldif

Sorry for the confusion....

Thank you very much - it works. I have two following questions:

  1. If you see below output, first and second column are overlapping, which parameter i should increase to accommodate longer values. can't this be dynamic? ( I know i am asking too much, but just in case you know something )
/apps/EIS/dir/slapd-dev_Operational/config/dse.ldifnsslapd-accesslog                        /export/apps/EIS/dir/slapd-dev_Operational/logs/access
/apps/EIS/dir/slapd-dev_Operational/config/dse.ldifnsslapd-accesslog-maxlogsperdir          10       
/apps/EIS/dir/slapd-dev_Operational/config/dse.ldifnsslapd-accesslog-logrotationtime        1        
/apps/EIS/dir/slapd-dev_Operational/config/dse.ldifnsslapd-accesslog-logrotationtimeunit    day      
/apps/EIS/dir/slapd-dev_Operational/config/dse.ldifnsslapd-accesslog-logging-enabled        on       
  1. Also, what are places i should change to add new fields.
  • John
nawk -F: 'BEGIN{fmt="%-50s%-40s%-10s%-20s\n";printf(fmt,"Path","Attribute","Value","myNewField")}tolower($1)~"nsslapd-accesslog*" {printf(fmt,FILENAME,$1,$2,$3)}'  /apps/EIS/dir/slapd-ED/config/dse.ldif
1 Like

Thank You !