Find and Replace Pattern in file

Ok, so how many times have you received this request? I have been looking through the forum for examples and I see the use of tr, awk and sed to perform similar functions but not sure how to use the tools in this scenario and could use a push in the right direction.

GOAL:
Search for line breaks and replace with a unique delimiter to import into excel
IDEALLY, create headers with the first part of each line (auth user, description, role) but I can manually remove by doing a search and replace like I will do with the last character { in auth user.

DATA: useraudit.txt

auth user SVC_Qualys {
    description "SVC_Qualys"
    role guest
auth user admin {
    description "Admin User"
    role admin
auth user svc_redseal {
    description "svc_redseal"
    role resource-admin

In my newbie ways I am trying to approach it step by step so first try and get everything on one line so I created users.awk

BEGIN {
        RS="\n\n";
        FS="\n";

}
{ print $1 ", " $2 ", " $3; } 

Ran awk -f users.awk useraudit.txt and I get
auth user SVC_Qualys {, description "SVC_Qualys", role guest

Not sure yet how to edit the results for the desired goal... I'll keep plugging away
Thank you for the community help. This forum has been a big help and I love the different ways people take to approach for a solution.

Some } missing? Are records ALWAYS three lines?

Yea, always three lines

I'm a bit puzzled on awk still but I have a feeling its the best approach.

I am thinking maybe this is a better script but its not working exactly like I was hoping.

BEGIN { i=0 }
{
if ($1 ~ /^ *auth/)
i=1
#print $3
auth=$3

if ($1 ~ /^ *description/)
i=i+1
#print $2 $3 $4
desc=$2 $3 $4

if ($1 ~ /^ *role/)
i=i+1
#print $2 $3 $4
role=$2 $3 $4

if (i=3)
print auth "," desc "," role
}  

Very simple proposal, just because further info is missing:

awk '
        {getline X; getline Y; print $0, X, Y
        }
' OFS=, file
auth user SVC_Qualys {,    description "SVC_Qualys",    role guest
auth user admin {,    description "Admin User",    role admin
auth user svc_redseal {,    description "svc_redseal",    role resource-admin

Some reason I am just not getting this to work.

The expected results based on the useraudit.txt file is

auth user,description,role
SVC_Qualys,SVC_Qualys,guest
admin,Admin User,admin
svc_redseal,svc_redseal,resource-admin

Which you didn't specify.

Sorry Rudi... I pasted the content in the first post.. i suppose i should of just attached the txt file.

contents of useraudit.txt

auth user SVC_Qualys {
    description "SVC_Qualys"
    role guest
auth user admin {
    description "Admin User"
    role admin
auth user svc_redseal {
    description "svc_redseal"
    role resource-admin

I was talking of the desired output (structure), not the input. How about

awk '
BEGIN   {HD = "auth user,description,role"
         n = split (HD, H, ",")
         print HD
        }
        {sub (H[(NR+2)%3+1], "")
         gsub (/[ {"]*/, "")   
         printf "%s%s", $0, NR%3?OFS:RS  
        }
' OFS=, file
auth user,description,role
SVC_Qualys,SVC_Qualys,guest
admin,AdminUser,admin
svc_redseal,svc_redseal,resource-admin

---------- Post updated at 20:57 ---------- Previous update was at 20:54 ----------

Unfortunately,the space in "Admin User" is gsub bed away. If need be, with some extra effort, it could be saved...

Thank You RudiC

I want to use your code but I'm obviously doing something wrong.

I copied your entire code, placed it in a file called test.awk and changed file to useraudit.txt which contains all the user information that we want to export

When I run test.awk I get

test.awk
-bash: test.awk: command not found 

When I run awk test.awk I get

awk test.awk
awk: test.awk
awk:     ^ syntax error  

And if I run awk -f test.awk I get

awk -f test.awk
awk: test.awk:1: awk '
awk: test.awk:1:     ^ invalid char ''' in expression

I know I need coffee and I can't wrap my head around what I'm doing wrong. I'll keep trying different things.

Copy the code in post#8 and paste it to the command line, adapt the file name, and it should fly!