File Parsing based on a character in a specific field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Parsing based on a character in a specific field
# 1  
Old 04-06-2015
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.

Code:
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

Code:
#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.
# 2  
Old 04-06-2015
Hi, try:
Code:
awk -F'[()]' '/^[^ \t]/{f=$2} {print>f}' file

--
Or if there are a lot more than 5 files:
Code:
awk -F'[()]' '/^[^ \t]/{close(f); f=$2} {print>>f}' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 04-06-2015
Try
Code:
awk '!/:/ && $NF~/^\(.*\)$/ {FN=$NF; gsub (/\(|\)/, "", FN)} {print $0 > FN}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Update a specific field in file with Variable value based on other Key Word

I have an input file with A=xyz B=pqr I would want the value in Second Field (xyz or pqr) updated with a value present in Shell Variable based on the value passed in the first field. (A or B ) while read line do NEW_VALUE = `some functionality done on $line` If $line=First Field-... (1 Reply)
Discussion started by: infernalhell
1 Replies

3. Shell Programming and Scripting

Perl to update field based on a specific set of rules

In the perl below, which does execute, I am having trouble with the else in Rule 3. The digit in f{8} is extracted and used to update f accordinly along with the value in f. There can be either - * or + before the number that is extracted but the same logic applies, that is if the value is greater... (5 Replies)
Discussion started by: cmccabe
5 Replies

4. Shell Programming and Scripting

Add specific string to last field of each line in perl based on value

I am trying to add a condition to the below perl that will capture the GTtag and place a specific string in the last field of each line. The problem is that the GT value used is not right after the tag rather it is a few fields away. The values should always be 0/1 or 1/2 and are in bold in the... (12 Replies)
Discussion started by: cmccabe
12 Replies

5. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

6. Shell Programming and Scripting

Combine multiple lines in file based on specific field

Hi, I have an issue to combine multiple lines of a file. I have records as below. Fields are delimited by TAB. Each lines are ending with a new line char (\n) Input -------- ABC 123456 abcde 987 890456 7890 xyz ght gtuv ABC 5tyin 1234 789 ghty kuio ABC ghty jind 1234 678 ght ... (8 Replies)
Discussion started by: ratheesh2011
8 Replies

7. Shell Programming and Scripting

Delete line based on count of specific character

I'm looking for what I hope might be a one liner along these lines: sed '/a line with more than 3 pipes in it/d' I know how to get the pipe count in a string and store it in a variable, but I'm greedy enough to hope that it's possible via regex in the /.../d context. Am I asking too much? ... (5 Replies)
Discussion started by: tiggyboo
5 Replies

8. Shell Programming and Scripting

File character adjustment based on specific character

i have a reqirement to adjust the data in a file based on a perticular character the sample data is as below 483PDEAN CORRIGAN 52304037528955WAGES 50000 89BP ABCD MASTER352 5434604223735428 4200 58BP SOUTHERN WA848 ... (1 Reply)
Discussion started by: pema.yozer
1 Replies

9. Shell Programming and Scripting

Help with replace character based on specific location

Hi, I got long list of reference file (column one is refer to the header in input file; column 2 is info of start position in input file; column 3 is info of end position in input file;) shown as below: read_2 10 15 read_3 5 8 read_1 4 10 . . . Input file (huge file with total... (6 Replies)
Discussion started by: perl_beginner
6 Replies

10. Shell Programming and Scripting

How to append a character to the last but one field on a specific line?

Hi Guys, I have a file like this: aaa b c d e f fsss g h i k l qqq r t h n I want: aaa b c d e f fsss g h i k l qqq r t h , n ggg p t e d u qqq i o s , k (2 Replies)
Discussion started by: npatwardhan
2 Replies
Login or Register to Ask a Question