File Parsing based on a character in a specific field

Hi All,

I'm having a hard time finding a starting point for my issue. I have a 30k line file (fspsec.txt) that I would like to parse into smaller files based on any character existing in field 1.

ACCOUNTANT LEVEL 1 (ACCT.ACCOUNTANT)
 OPERATORS: DOEJO (418)
     TOOLS: Branch Maintenance
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can view/edit any branch?                                               Y
            Transaction History
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can waive check copy viewing fee?                                       N
ACCOUNTANT SUPERVISOR (ACCT.SUPERVISOR)
 OPERATORS: DOEJO (C11)
     TOOLS: AP 1099-MISC Maintenance
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
            Transaction History
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can alter check copy viewing fee amount?                                N
ACCOUNTING MANAGER (ACCT.MANAGER)
 OPERATORS: None
     TOOLS: ACH Stop Payment
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
            Verification of Deposits
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 No Security Questions
ATM DEBIT CARD GROUP (DEBIT.GROUP)
 OPERATORS: None
     TOOLS: 10 Key Calculator
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 No Security Questions
            ACH Stop Payment
                 Security Question                                                       Security ?
                 Can operator process certificate debits?                                N
BACK OFFICE IT MANAGER (BO.MANAGER)
 OPERATORS: DOEJO (888)
     TOOLS: ACH Administration
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can alter telamon scripts?                                              Y
            ACH Distributions
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can Add ACH distributions?                                              Y

Ideally the above could be parsed into 5 separate files uniquely named:
ACCT.ACCOUNTANT
ACCT.SUPERVISOR
ACCT.MANAGER
DEBIT.GROUP
BO.MANAGER

#more ACCT.ACCOUNTANT
ACCOUNTANT LEVEL 1 (ACCT.ACCOUNTANT)
 OPERATORS: DOEJO (418)
     TOOLS: Branch Maintenance
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can view/edit any branch?                                               Y
            Transaction History
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can waive check copy viewing fee?                                       N

#more ACCT.SUPERVISOR
ACCOUNTANT SUPERVISOR (ACCT.SUPERVISOR)
 OPERATORS: DOEJO (C11)
     TOOLS: AP 1099-MISC Maintenance
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
            Transaction History
                 Security Question                                                       Security ?
                 -----------------                                                       ----------
                 Can alter check copy viewing fee amount?                                N

Any direction or thoughts would be appreciated.

Hi, try:

awk -F'[()]' '/^[^ \t]/{f=$2} {print>f}' file

--
Or if there are a lot more than 5 files:

awk -F'[()]' '/^[^ \t]/{close(f); f=$2} {print>>f}' file
1 Like

Try

awk '!/:/ && $NF~/^\(.*\)$/ {FN=$NF; gsub (/\(|\)/, "", FN)} {print $0 > FN}' file