gawk print some special lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gawk print some special lines
# 1  
Old 03-07-2009
gawk print some special lines

Hi every body,

i have this file example :

TD1
TD2
TD3
.
.
.TDn

<DIE_1>
xxxxxx
<\DIE_1>
<TD1>
information 1
inormation n
<\TD1>
<TDq>
information
<\TD_q>
.
.
.
<DIE_m>
xxxxxx
<\DIE_m>
<TD3>
information 1
inormation n
<\TD3>
<TDP>
information
<\TD_p>


for example i can find TD3 in DIE_n and in DIE_p and this is true for each TD.

i want to print in each new file information of TDn and relative DIE where i find it, for example if TD3 is in DIE_n and DIE_p i will print this two files :

file1
<DIE_n>
xxxxxx
<\DIE_n>
<TD3>
information 1
inormation n
<\TD3>

file 2

<DIE_p>
xxxxxx
<\DIE_p>
<TD3>
information 1
inormation n
<\TD3>

please note that the information in TD3 of each DIE is not similar to the other.

who can use gawk for example to do that, it's hard for me.

many thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk Find Pattern Print Lines Before and After

Using grep I can easily use: cvs log |grep -iB 10 -A 10 'date: 2013-10-30' to display search results and 10 lines before and after. How can this be accompished using gawk? (4 Replies)
Discussion started by: metallica1973
4 Replies

2. Shell Programming and Scripting

Print every 5 lines with special condition

Hi Friends, I have an input file like this chr1 100 200 chr1 200 300 chr1 300 400 chr1 400 500 chr1 500 600 chr1 600 700 chr1 700 800 chr1 800 900 chr1 900 920 chr1 940 960 I would like to get the first line's second column and the fifth line's 3rd column as one single line. This... (13 Replies)
Discussion started by: jacobs.smith
13 Replies

3. Shell Programming and Scripting

How to print log of gawk

I have used gawk inside my script. But doesn't make log of that. So, what is the way to make logs of gawk block Thanks for replying...:) (3 Replies)
Discussion started by: ezee
3 Replies

4. Shell Programming and Scripting

Merging Adjacent Lines Using Gawk

Hi all, I have a text file consisting of 4 columns. What I am trying to do is see whether column 2 repeats multiple times, and collapse those repeats into one row. For example, here is a snippet of the file I am trying to analyze: 1 Gamble_Win 14.282 0.502 1 Sure_Thing 14.858 0.174 1... (4 Replies)
Discussion started by: Jahn
4 Replies

5. Shell Programming and Scripting

Gawk / Awk Merge Lines based on Key

Hi Guys, After windows died on my netbook I installed Lubuntu and discovered Gawk about a month ago. After using Excel for 10+ years I'm amazed how quick and easily Gawk can process data but I'm stuck with a little problem merging data from multiple lines. I'm an SEO Consultant and provide... (9 Replies)
Discussion started by: Jamesfirst
9 Replies

6. Shell Programming and Scripting

print lines AFTER lines cointaining a regexp (or print every first and fourth line)

Hi all, This should be very easy but I can't figure it out... I have a file that looks like this: @SRR057408.1 FW8Y5CK02R652T length=34 AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT +SRR057408.1 FW8Y5CK02R652T length=34 FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8 @SRR057408.2 FW8Y5CK02TBMHV length=52... (1 Reply)
Discussion started by: kmkocot
1 Replies

7. UNIX for Dummies Questions & Answers

JOINING MULTIPLE LINES IN A TEXT FILE USING GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. I WANT THE DATA... (0 Replies)
Discussion started by: KANNI786
0 Replies

8. UNIX for Dummies Questions & Answers

Joining lines of a text file using GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. ... (0 Replies)
Discussion started by: KANNI786
0 Replies

9. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

10. Shell Programming and Scripting

Gawk combining lines unexpectedly

I am attempting to combine sections of log that should be one line but are spaced out over 10-30 lines due to how the software is outputting the info. (If I am making a newbie mistake I apologize) Example of log I am working with: 2009-04-14 14:51:22 access data here info. Info. Info. ……..... (4 Replies)
Discussion started by: demanche
4 Replies
Login or Register to Ask a Question
MboxParser::Mail::Body(3pm)				User Contributed Perl Documentation			       MboxParser::Mail::Body(3pm)

NAME
Mail::MboxParser::Mail::Body - rudimentary mail-body object SYNOPSIS
use Mail::MboxParser; [...] # $msg is a Mail::MboxParser::Mail my $body = $msg->body(0); # or preferably my $body = $msg->body($msg->find_body); for my $line ($body->signature) { print $line, " " } for my $url ($body->extract_urls(unique => 1)) { print $url->{url}, " "; print $url->{context}, " "; } DESCRIPTION
This class represents the body of an email-message. Since emails can have multiple MIME-parts and each of these parts has a body it is not always easy to say which part actually holds the text of the message (if there is any at all). Mail::MboxParser::Mail::find_body will help and suggest a part. METHODS
as_string ([strip_sig => 1]) Returns the textual representation of the body as one string. Decoding takes place when the mailbox has been opened using the decode => 'BODY' | 'ALL' option. If 'strip_sig' is set to a true value, the signature is stripped from the string. as_lines ([strip_sig => 1]) Sames as as_string() just that you get an array of lines with newlines attached to each line. NOTE: When the body is actually some encoded binary data (most commonly such a body is base64-encoded), you can still use this method. Then you wont really get proper lines. Instead you get chunks of binary data that you should concatenate as in my $binary = join "", $body->as_lines; If 'strip_sig' is set to a true value, the signature is stripped from the string. signature Returns the signature of a message as an array of lines. Trailing newlines are already removed. $body->error returns a string if no signature has been found. extract_urls extract_urls (unique => 1) Returns an array of hash-refs. Each hash-ref has two fields: 'url' and 'context' where context is the line in which the 'url' appeared. When calling it like $mail->extract_urls(unique => 1), duplicate URLs will be filtered out regardless of the 'context'. That's useful if you just want a list of all URLs that can be found in your mails. $body->error() will return a string if no URLs could be found within the body. quotes Returns a hash-ref of array-refs where the hash-keys are the several levels of quotation. Each array-element contains the paragraphs of this quotation-level as one string. Example: my $quotes = $msg->body($msg->find_body)->quotes; print $quotes->{1}->[0], " "; print $quotes->{0}->[0], " "; This should print the first paragraph of the mail-body that has been quoted once and below that the paragraph that supposedly is the reply to this paragraph. Perhaps thus: > I had been trying to work with the CGI module > but I didn't yet fully understand it. Ah, it is tricky. Have you read the CGI-FAQ that comes with the module? Mark that empty lines will not be ignored and are part of the lines contained in the array of $quotes->{0}. So below is a little code-snippet that should, in most cases, restore the first 5 paragraphs (containing quote-level 0 and 1) of an email: for (0 .. 4) { print $quotes->{0}->[$_]; print $quotes->{1}->[$_]; } Since quotes() considers an empty line between two quotes paragraphs as a paragraph in $quotes->{0}, the paragraphs with one quote and those with zero are balanced. That means: scalar @{$quotes->{0}} - DIFF == scalar @{$quotes->{1}} where DIFF is element of {-1, 0, 1}. Unfortunately, quotes() can up to now only deal with '>' as quotation-marks. VERSION
This is version 0.55. AUTHOR AND COPYRIGHT
Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de> Copyright (c) 2001-2005 Tassilo von Parseval. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl v5.12.3 2005-12-08 MboxParser::Mail::Body(3pm)