Perl program to print previous set of lines once a pattern is matched


 
Thread Tools Search this Thread
Operating Systems Linux Perl program to print previous set of lines once a pattern is matched
# 1  
Old 05-22-2012
Perl program to print previous set of lines once a pattern is matched

Hi all,

I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in this case. AN example of a record is given below. If the program finds FIELD AV for a record, I want to get first 3 lines say till FIELD TX for very record and lines after FIELD AV till FIELD RF. I want a perl program

CODE
Code:
#!/usr/bin/perl
open(DATA, 'generecordsdata.txt');
# or die("Could not open generecordsdata file.");
open(MYOUTPUT, ">mutationsdata.txt");
# or die ("could not open mutationsdata file.");
while(<DATA>)
{
if (/^\*FIELD\*\sAV$/)
{
print $_=<DATA> until /^\*FIELD\*\sRF$/ ;
}
}
close(MYOUTPUT);
close(DATA);



Code:
*100710 CHOLINERGIC RECEPTOR, NICOTINIC, BETA POLYPEPTIDE 1; CHRNB1
;;CHRNB;;
ACETYLCHOLINE RECEPTOR, MUSCLE, BETA SUBUNIT; ACHRB
*FIELD* TX
For background information on the acetylcholine receptor, see CHRNA1
(100690).
BIOCHEMICAL FEATURES
By recording images at liquid-helium temperatures and applying a
computational method to correct for distortions, Miyazawa et al. (2003)
reported the crystal structure of the acetylcholine receptor of the
Torpedo electric ray at a resolution of 4 angstroms. The pore is shaped
by an inner ring of 5 alpha helices, which curve radially to create a
tapering path for the ions, and an outer ring of 15 alpha helices, which
coil around each other and shield the inner ring from the lipids. The
gate is a constricting hydrophobic girdle at the middle of a lipid
bilayer, formed by weak interactions between neighboring inner helices.
When acetylcholine enters the ligand-binding domain, it triggers
rotations of the protein chains on opposite sides of the entrance to the
pore. These rotations are communicated through the inner helices and
open the pore by breaking the girdle apart.
MAPPING
In the Torpedo (electric ray), the 4 subunits of the AChR show
conspicuous sequence homology. Heidmann et al. (1986) analyzed
restriction fragment length polymorphisms of each of the 4 subunits of
muscle nicotinic acetylcholine receptor in crosses between 2 mouse
species. They found that the beta subunit gene is located on mouse
chromosome 11. The beta subunit gene was found to be tightly linked with
the locus encoding the different isoforms (embryonic, perinatal and
adult) of the myosin heavy chain genes which are located on mouse
chromosome 11. In man these genes are located on chromosome 17p
(160730), arguing from likely homology of synteny. The beta subunit of
the acetylcholine receptor may be coded by a gene on human 17p also.
Using a panel of human-rodent somatic cell hybrids segregating human
chromosomes, Beeson et al. (1989) demonstrated that the CHRNB locus is
on human chromosome 17. Beeson et al. (1990) regionalized the CHRNB gene
to 17p12-p11 by in situ hybridization.
MOLECULAR GENETICS
In a patient with slow-channel congenital myasthenic syndrome (601462),
Engel et al. (1996) identified a heterozygous mutation in the CHRNB1
gene (100710.0001).
In 3 sibs with congenital myasthenic syndrome associated with
acetylcholine receptor deficiency (608931), Quiram et al. (1999)
identified compound heterozygosity for 2 mutations in the CHRNB1 gene
(100710.0003; 100710.0004).
*FIELD* AV
.0001
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, VAL266MET
In a 19-year-old female with slow-channel congenital myasthenic syndrome
(601462), Engel et al. (1996) identified a heterozygous 796G-A
transition in exon 8 of the CHRNB1 gene, resulting in a val266-to-met
(V266M) substitution in a conserved residue in the M2 transmembrane
domain of the AChR-beta subunit. Functional expression studies showed
that the V266M mutation slowed the rate of AChR channel closure and
increased the apparent affinity for ACh. The mutation also caused
pathologic channel openings even in the absence of ACh, resulting in a
leaky channel. Cationic overload of the postsynaptic region caused an
endplate myopathy.
.0002
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, LEU263MET
In a 32-year-old male with slow-channel congenital myasthenic syndrome
(601462), Gomez et al. (1996) identified a heterozygous C-to-A
transversion in the CHRNB1 gene, resulting in a leu263-to-met (L263M)
substitution. Functional expression studies showed that the L263M
mutation interrupted the leucine ring of the AChR channel gate, causing
an 8-fold increase in channel open time and resulting in severe endplate
myopathy and extensive remodeling of the postsynaptic membrane. The
pronounced abnormalities in neuromuscular synaptic architecture and
function and the muscle fiber damage and weakness resulting from a
single point mutation were a dramatic example of a mutation having a
dominant gain of function and of hereditary excitotoxicity.
.0003
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, 9-BP DEL, NT1276 
In 3 sibs with congenital myasthenia and AChR deficiency (608931),
Quiram et al. (1999) identified compound heterozygosity for 2 mutations
in the CHRNB1 gene. One mutation was a 9-bp deletion (1276del9) in exon
10, resulting in a deletion of 3 codons (426-428) in the long
cytoplasmic loop between the M3 and M4 domains of the protein. The
second mutation was a skipping of exon 8 (100710.0004), truncating the
beta subunit before its M1 transmembrane domain and abolishing surface
expression of pentameric AChR. By coexpressing the 3-codon deleted
subunit with combinations of wildtype subunits in HEK293 cells, Quiram
et al. (1999) demonstrated that the mutation impairs AChR assembly by
disrupting a specific interaction between the beta and delta (100720)
subunits. Studies with related deletion and missense mutations indicated
that secondary structure in this region of the beta subunit is crucial
for interaction with the delta subunit. The findings implied that the
mutated residues are positioned at the interface between beta and delta
subunits and demonstrated contribution of this local region of the long
cytoplasmic loop to AChR assembly.
.0004
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, EX8DEL 
See 100710.0003 and Quiram et al. (1999).
*FIELD* SA
Beeson et al. (1989)
*FIELD* RF


Moderator's Comments:
Mod Comment Please view this link: How to use [code]...[/code] tags

Last edited by Scrutinizer; 05-22-2012 at 02:06 AM.. Reason: code tags
# 2  
Old 05-22-2012
Hi, could you post a sample of what you would want your output to look like given your input sample?
# 3  
Old 05-22-2012
Hi Scrutinizer,

The expected output is given below:

Code:
*100710 CHOLINERGIC RECEPTOR, NICOTINIC, BETA POLYPEPTIDE 1; CHRNB1
;;CHRNB;;
ACETYLCHOLINE RECEPTOR, MUSCLE, BETA SUBUNIT; ACHRB
*FIELD* AV
.0001
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, VAL266MET
In a 19-year-old female with slow-channel congenital myasthenic syndrome
(601462), Engel et al. (1996) identified a heterozygous 796G-A
transition in exon 8 of the CHRNB1 gene, resulting in a val266-to-met
(V266M) substitution in a conserved residue in the M2 transmembrane
domain of the AChR-beta subunit. Functional expression studies showed
that the V266M mutation slowed the rate of AChR channel closure and
increased the apparent affinity for ACh. The mutation also caused
pathologic channel openings even in the absence of ACh, resulting in a
leaky channel. Cationic overload of the postsynaptic region caused an
endplate myopathy.
.0002
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, LEU263MET
In a 32-year-old male with slow-channel congenital myasthenic syndrome
(601462), Gomez et al. (1996) identified a heterozygous C-to-A
transversion in the CHRNB1 gene, resulting in a leu263-to-met (L263M)
substitution. Functional expression studies showed that the L263M
mutation interrupted the leucine ring of the AChR channel gate, causing
an 8-fold increase in channel open time and resulting in severe endplate
myopathy and extensive remodeling of the postsynaptic membrane. The
pronounced abnormalities in neuromuscular synaptic architecture and
function and the muscle fiber damage and weakness resulting from a
single point mutation were a dramatic example of a mutation having a
dominant gain of function and of hereditary excitotoxicity.
.0003
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, 9-BP DEL, NT1276 
In 3 sibs with congenital myasthenia and AChR deficiency (608931),
Quiram et al. (1999) identified compound heterozygosity for 2 mutations
in the CHRNB1 gene. One mutation was a 9-bp deletion (1276del9) in exon
10, resulting in a deletion of 3 codons (426-428) in the long
cytoplasmic loop between the M3 and M4 domains of the protein. The
second mutation was a skipping of exon 8 (100710.0004), truncating the
beta subunit before its M1 transmembrane domain and abolishing surface
expression of pentameric AChR. By coexpressing the 3-codon deleted
subunit with combinations of wildtype subunits in HEK293 cells, Quiram
et al. (1999) demonstrated that the mutation impairs AChR assembly by
disrupting a specific interaction between the beta and delta (100720)
subunits. Studies with related deletion and missense mutations indicated
that secondary structure in this region of the beta subunit is crucial
for interaction with the delta subunit. The findings implied that the
mutated residues are positioned at the interface between beta and delta
subunits and demonstrated contribution of this local region of the long
cytoplasmic loop to AChR assembly.
.0004
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, EX8DEL 
See 100710.0003 and Quiram et al. (1999).
*FIELD* SA
Beeson et al. (1989)
*FIELD* RF


Last edited by kaav06; 05-25-2012 at 05:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

2. Shell Programming and Scripting

Sed: how to merge two lines moving matched pattern to end of previous line

hello everyone, im new here, and also programming with awk, sed and grep commands on linux. In my text i have many lines with this config: 1 1 4 3 1 1 2 5 2 2 1 1 1 3 1 2 1 3 1 1 1 2 2 2 5 2 4 1 3 2 1 1 4 1 2 1 1 1 3 2 1 1 5 4 1 3 1 1... (3 Replies)
Discussion started by: satir
3 Replies

3. Shell Programming and Scripting

Print only matched pattern in perl

Hi, I have script like below: #!/usr/local/bin/perl use strict; use warnings; while (<DATA>) { ( my ($s_id) = /^\d+\|(\d+?)\|/ ) ; if ( $s_id == 1 ){ s/^(.*\|)*.*ABC\.pi=(+|+)*.*ABC\.id=(\d+|+).*$/$1$2|$3/s; print "$1$2|$3\n"; (2 Replies)
Discussion started by: sol_nov
2 Replies

4. Shell Programming and Scripting

print range of lines matching pattern and previous line

Hi all, on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern. the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/' I need to include the... (1 Reply)
Discussion started by: siriche
1 Replies

5. Shell Programming and Scripting

sed: how to move matched pattern to end of previous line

Hello, I'm new to this forum. I've been doing a lot of sed work lately and have found many useful tips on this forum. I've hit a roadblock in a project, though, and could really use some help. I have a text file with many lines like the following, i.e., some lines begin with a single word... (3 Replies)
Discussion started by: paroikoi
3 Replies

6. Shell Programming and Scripting

perl script print the lines between two pattern

i have a file as below sample.pl parameter1 argument1 argument2 parameter2 I want out as below argument1 argument2 that is , i want to print all the lines between parameter1 & parameter 2. i tried with the following if($mystring =~ m/parameter1(.*?)parameter2/) (2 Replies)
Discussion started by: roopa
2 Replies

7. Shell Programming and Scripting

Search for a pattern in a file and print previous lines from a particular point

Hi, I am new to ksh scripting and I have a problem. I have a file in which I have to search for a particular pattern say 'a' then from that line I need to search for another pattern say 'b' in the previous lines and thne print the file from pattern 'b' till the end of file. For eg: ... (2 Replies)
Discussion started by: umaislearning
2 Replies

8. Shell Programming and Scripting

Perl script to match a pattern and print lines

Hi I have a file (say 'file1')and I want to search for a first occurence of pattern (say 'ERROR') and print ten lines in the file below pattern. I have to code it in PERL and I am using Solaris 5.9. I appreciate any help with code Thanks Ammu (6 Replies)
Discussion started by: ammu
6 Replies

9. Shell Programming and Scripting

How to print lines till till a pattern is matched in loop

Dear All I have a file like this 112534554 446538656 444695656 225696966 226569744 228787874 113536566 443533535 222564552 115464656 225445345 225533234 I want to cut the file into different parts where the first two columns are '11' . The first two columns will be either... (3 Replies)
Discussion started by: anoopvraj
3 Replies

10. Shell Programming and Scripting

print last matched pattern using perl

Hi, If there exist multiple pattern in a file, how can I find the last record matching the pattern through perl. The below script searches for the pattern everywhere in an input file. #! /usr/bin/perl -s -wnl BEGIN { $pattern or warn"Usage: $0 -pattern='RE' \n" and exit 255;... (5 Replies)
Discussion started by: er_ashu
5 Replies
Login or Register to Ask a Question