parsing characters and number from a big file with brackets


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing characters and number from a big file with brackets
# 1  
Old 03-14-2012
parsing characters and number from a big file with brackets

I have a big file with many brackets () in it from which I need to parse number characters and numbers. Below is an example of my file

Code:
14 (((A__0:0.02,B__1:0.3)0:0.04,C__0:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362;
15 (((A__3:0.02,B__1:0.3)2:0.04,C__1:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362;
20 (((A__1:0.02,B__1:0.3)0:0.04,C__2:0.025)1:0.01),(D__4:0.00978,E__2:0.01031)2:0.00362;
..
..
...
...

I want to parse out the values and characters starting from each of the inner brackets and out put in a line in such a way that the numerical value just outside an inner bracket comes first followed by the number associated with the character (for A__0 A and 0). An example of the desired output is given below

Code:
14
0 A 0 B 1
2 C 0
1 D 0 E 2

15
2 A 3 B 1
2 C 2
1 D 0 E 2

20
0 A 1 B 1
1 C 2
2 D 4 E 2

Please let me know the best way to parse this using awk or sed.
# 2  
Old 03-14-2012
One way...
Code:
$ cat file1
14 (((A__0:0.02,B__1:0.3)0:0.04,C__0:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362;
15 (((A__3:0.02,B__1:0.3)2:0.04,C__1:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362;
20 (((A__1:0.02,B__1:0.3)0:0.04,C__2:0.025)1:0.01),(D__4:0.00978,E__2:0.01031)2:0.00362;

$ awk -F '[(_:,)]' '{print $1 ORS $12, $4, $6, $8, $10 ORS $18, $14, $16 ORS $28, $22, $24, $26, $28 ORS}' file1
14
0 A 0 B 1
2 C 0
2 D 0 E 2

15
2 A 3 B 1
2 C 1
2 D 0 E 2

20
0 A 1 B 1
1 C 2
2 D 4 E 2


$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file containing special characters

I want to parse a file containing special characters, below is a sample content of file content of file : Serial_no:1$$@#first_name:Rahane$$@last_name:Ajiyenke@@#profession:cricketer!@#*&^ Serial_no:1$$@#first_name:Rahane$$@last_name:Ajiyenke@@#profession:cricketer!@#*&^... (3 Replies)
Discussion started by: rajMjar
3 Replies

2. Shell Programming and Scripting

Parsing log file and print latest number in loop

Hello All, I have an awk script which parses my log file and prints number grepping from a specific line/pattern, now i have to come with a shell script to continue reading the log untill the job is completed, which i would know while reading session log untill process encounters a final... (1 Reply)
Discussion started by: Ariean
1 Replies

3. Shell Programming and Scripting

Grep number between Square [] brackets

I wanted to store the number inside the square bracket between colon( : ) and closing suqre bracket(]) in some variable. Suppose I have lines like : Input file : 20140320 00:08:23.846 INFO 84] - anything in line 20140320 00:08:23.846 Test 589] - Virtual and lab lab anything... (18 Replies)
Discussion started by: nes
18 Replies

4. Shell Programming and Scripting

Split a big file into multiple files based on first four characters

I have a requirement to split a huge file to smaller text files based on first four characters which look like ABCD 1234 DFGH RREX : : : : : 0000 Each of these records are OF EQUAL bytes with a different internal layout based on the above first digit identifier.. Any help to start... (5 Replies)
Discussion started by: etldev
5 Replies

5. Shell Programming and Scripting

parsing data from a big file using keys from another smaller file

Hi, I have 2 files format of file 1 is: a1 b2 a2 c2 d1 f3 format of file 2 is (tab delimited): a1 1.2 0.5 0.06 0.7 0.9 1 0.023 a3 0.91 0.007 0.12 0.34 0.45 1 0.7 a2 1.05 2.3 0.25 1 0.9 0.3 0.091 b1 1 5.4 0.3 9.2 0.3 0.2 0.1 b2 3 5 7 0.9 1 9 0 1 b3 0.001 1 2.3 4.6 8.9 10 0 1 0... (10 Replies)
Discussion started by: Lucky Ali
10 Replies

6. Shell Programming and Scripting

parsing file based on characters/bytes

I have a datafile that is formatted as fixed. I know that each line should contain 880 characters. I want to separate the file into 2 files, one that has lines with 880 characters and the other file with everything else. Is this possible ? (9 Replies)
Discussion started by: cheeko111
9 Replies

7. Shell Programming and Scripting

parsing a file name and add a number

Hi, I have a file po8282.fmt998.fbi.mopac.x.macs.btt.txt . I want to parse the first field which is separated by "." and then find the number and add 1 to it. here is what I am doing to get the first field, but not sure how to only pick the number and add 1 to it... (5 Replies)
Discussion started by: rudoraj
5 Replies

8. Shell Programming and Scripting

Helping in parsing subset of text from a big results file

Hi All, I need some help to effectively parse out a subset of results from a big results file. Below is an example of the text file. Each block that I need to parse starts with "reading sequence file 10.codon" (next block starts with another number) and ends with **p-Value(s)**. I have given... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

9. AIX

How to cut a flat file according to a certain number of characters?

hello everybody i am looking for a shell to cut a flat file (with a long unique line) according to a certain number of characters and redirect every result to an output file. here is an example MyFile : 12 3 456 12 3 456 12 3 456 ..... and i took every 9-characters including BLANKS... (6 Replies)
Discussion started by: fastlane3000
6 Replies

10. UNIX and Linux Applications

handling maximum number characters in an input file

Hi, Can anyone help me? An input file has three lines. Each line should only be 2098 as number of characters however line 2 of the input file has more than the maximum number of characters, it exceeded up to 4098. What should I do so that could handle maximum number of characters? that it could... (1 Reply)
Discussion started by: chrysSty
1 Replies
Login or Register to Ask a Question