multiple line parsing help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers multiple line parsing help
# 1  
Old 07-11-2009
multiple line parsing help

Hey everyone,

I'm having trouble figuring out how to reformat the following (large) file:

>Cluster 1
0 563nt, >FX2FH6V05GB01A... *
1 405nt, >FX2FH6V05F7LOL... at +/98%
>Cluster 2
0 551nt, >FX2FH6V05FTLO0... at +/98%
1 561nt, >FX2FH6V05F5F1E... *
2 343nt, >FX2FH6V05GBHRK... at +/98%

I need to reformat it so that the string in front of the asterisk is first on a line, followed by that string repeated, and the all of the other strings in the cluster. For example:
FX2FH6V05GB01A FX2FH6V05GB01A, FX2FH6V05F7LOL
FX2FH6V05F5F1E FX2FH6V05F5F1E, FX2FH6V05FTLO0, FX2FH6V05GBHRK

Some of the clusters are very large, and the string followed by the asterisk can be anywhere within that cluster. I can probably figure out how to flatten everything, but I'm not sure how to reorder the strings so that the one with the asterisk comes first.

Many thanks in advance for your advice.
# 2  
Old 07-13-2009
Try...
Code:
awk '/>Cluster/{c=$2;next}
     {z=substr($3,2,14);if($NF=="*")b[c]=z;else a[c]=a[c] "," z}
     END{for(c in b)print b[c] " " b[c] a[c]}' file1

Result...
Code:
FX2FH6V05GB01A FX2FH6V05GB01A,FX2FH6V05F7LOL
FX2FH6V05F5F1E FX2FH6V05F5F1E,FX2FH6V05FTLO0,FX2FH6V05GBHRK

# 3  
Old 07-13-2009
Thanks Ygor!

You solved a problem in a few minutes that I've been struggling with for a week. The parser works great.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing out data with multiple field separators

I have a large file that I need to print certain sections out of. file.txt /alpha/beta/delta/gamma/425/590/USC00015420.blah.lt.0.01.str:USC00015420Y2017M10BLALT.01 12 13 14 -9 1 -9 -9 -9 -9 -9 1 2 3 4 5 -9 -9 I need to print the "USC00015420" and... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

2. Shell Programming and Scripting

String parsing help across multiple UNIX platforms

Need to parse XML like strings from a file. Using `egrep -A 1 "Panel Temp" "$2" | tail -2` I get the following string: <parameter name="Panel Temp" unit="0.1 C"> <value size="1" starttime="06-08-2017 09:36:56.968">95</value> I want to output: {"Panel Temp" 9.5 C} The 9.5 C is the value... (16 Replies)
Discussion started by: harleyvrodred
16 Replies

3. Shell Programming and Scripting

Parsing common values across multiple files

Hi All, I have multiple (5+) text files with single columns and I would like to grep the common values across all the text files and parse it to a new file. All the values are numerical. Please let me know how to do it using awk. (6 Replies)
Discussion started by: Lucky Ali
6 Replies

4. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

5. Shell Programming and Scripting

Logfile parsing with variable, multiple criterias among multiple lines

Hi all I've been working on a bash script parsing through debug/trace files and extracting all lines that relate to some search string. So far, it works pretty well. However, I am challenged by one requirement that is still open. What I want to do: 1) parse through a file and identify all... (3 Replies)
Discussion started by: reminder
3 Replies

6. Shell Programming and Scripting

Parsing record into multiple records in Shell Script

Hi, I am trying to parse a very long record in a text file into multiple records by checking ADD, DELETE, or MODIFY field value in a shell script. Input # File name xyz.txt ADD|N000|8015662|DELETE|N001|9915662|MODIFY|N999|85678 Output ADD|N000|8015662| DELETE|N001|9915662|... (8 Replies)
Discussion started by: naveed
8 Replies

7. Shell Programming and Scripting

parsing a file by line

I'm trying to make a script that will read variables line by line from a flatfile i.e. $ cat testfile dbfoo sfoo prifoo poofoo bfoo osfoo dbfoo2 sfoo2 prifoo2 poofoo2 bfoo2 osfoo2 $ The first pass of the script through the flatfile I want: $1=dbfoo $2=sfoo... (6 Replies)
Discussion started by: loadnabox
6 Replies

8. Shell Programming and Scripting

Perl question, parsing line by line

Hello, Im very new to PERL and as a project to work on developing my skills at PERL Im trying to parse poker hands. Ive tried many methods however I cant get the last step. $yourfile= 'FILENAME';#poker hands to parse open (FILE, "$yourfile") or die $!; @lines = <FILE>; for (@lines) ... (1 Reply)
Discussion started by: Ek0
1 Replies

9. Shell Programming and Scripting

Parsing line out of a file, please help !!

Hello, I have a file with several lines for example; I need to extract a line radiusAuthServTotalAccessRequests.0 = 0 and I don't have line #s in the file. I need to write a script to extract the above line, put a date beside it and parse this line out to another directory / file. How... (5 Replies)
Discussion started by: xeniya
5 Replies

10. Shell Programming and Scripting

parsing a delimited line

I have a text file of lines like: A=5|B=7|G=4|C=3|P=4|... In other words, each line is a pipe-delimited set of pairs of strings of the form "X=Y". What I want to do is find the token starting with "C", and print it and its value (so I'd want to print "C=3" in the example above). I'm... (11 Replies)
Discussion started by: monkeys
11 Replies
Login or Register to Ask a Question