3

I have a file with number of 'blocks' (three blocks in this example) that look like this:

A4_RAT  Amyloid-beta A4 protein;    P08592  PDB; 1M7E; X-ray; 2.45 A; D/E/F=755-763.
                                    PDB; 1NMJ; NMR; -; A=672-699.
                                    PDB; 1OQN_I3P.pdb; X-ray; 2.30 A; C/D=755-763.
                                    PDB; 2LI9; NMR; -; A/B=672-687.

AACP_AGRFC  Aminoacyl carrier protein;  A9CHM9          PDB; 2JQ4; NMR; -; A=1-83.
                                    PDB; 4H2W_5GP.pdb; X-ray; 1.95 A; C/D=1-83.
                                    PDB; 4H2X_G5A.pdb; X-ray; 2.15 A; C/D=1-83.
                                    PDB; 4H2Y; X-ray; 2.10 A; C/D=1-83.

AADB1_KLEPN 2''-aminoglycoside nucleotidyltransferase;  P0AE05  PDB; 4WQK; X-ray; 1.48 A; A=1-177.
                                    PDB; 4WQL; X-ray; 1.73 A; A=1-177.
                                    PDB; 5KQJ_GOL.pdb; NMR; -; A=1-177.

Each 'block' has PDB;, XXXX/XXXX_XXX.pdb;, Xray/NMR; columns. From the last two columns from the previous sentence (XXXX; or XXXX_XXX.pdb; and X-ray; or NMR;) there are several options that I am encountering within each block:

XXXX; X-ray;
XXXX_XXX.pdb; X-ray;
XXXX; NMR;
XXXX_XXX.pdb; NMR;

I am trying to search only for those 'blocks' that have only XXXX_XXX.pdb; X-ray; and only for those 'blocks' that have only XXXX_XXX.pdb; NMR;.

From the example here, if I do the search for those that have only XXXX_XXX.pdb; X-ray; I am expecting result to be:

A4_RAT  Amyloid-beta A4 protein;    P08592  PDB; 1M7E; X-ray; 2.45 A; D/E/F=755-763.
                                    PDB; 1NMJ; NMR; -; A=672-699.
                                    PDB; 1OQN_I3P.pdb; X-ray; 2.30 A; C/D=755-763.
                                    PDB; 2LI9; NMR; -; A/B=672-687.

AACP_AGRFC  Aminoacyl carrier protein;  A9CHM9          PDB; 2JQ4; NMR; -; A=1-83.
                                    PDB; 4H2W_5GP.pdb; X-ray; 1.95 A; C/D=1-83.
                                    PDB; 4H2X_G5A.pdb; X-ray; 2.15 A; C/D=1-83.
                                    PDB; 4H2Y; X-ray; 2.10 A; C/D=1-83.

On the other hand, if I do the search for those that have only XXXX_XXX.pdb; NMR; I am expecting result to be:

AADB1_KLEPN 2''-aminoglycoside nucleotidyltransferase;  P0AE05  PDB; 4WQK; X-ray; 1.48 A; A=1-177.
                                    PDB; 4WQL; X-ray; 1.73 A; A=1-177.
                                    PDB; 5KQJ_GOL.pdb; NMR; -; A=1-177.

Does anybody has idea how to do it in bash?

2

Asuming you have empty lines between each block as you show in your question, so:

$ awk -v RS='\n\n' '/...._...\.pdb; NMR;/' RS= infile
AADB1_KLEPN 2''-aminoglycoside nucleotidyltransferase;  P0AE05  PDB; 4WQK; X-ray; 1.48 A; A=1-177.
                                    PDB; 4WQL; X-ray; 1.73 A; A=1-177.
                                    PDB; 5KQJ_GOL.pdb; NMR; -; A=1-177.

$ awk -v RS='\n\n' '/...._...\.pdb; X-ray;/' RS= infile
A4_RAT  Amyloid-beta A4 protein;    P08592  PDB; 1M7E; X-ray; 2.45 A; D/E/F=755-763.
                                    PDB; 1NMJ; NMR; -; A=672-699.
                                    PDB; 1OQN_I3P.pdb; X-ray; 2.30 A; C/D=755-763.
                                    PDB; 2LI9; NMR; -; A/B=672-687.
AACP_AGRFC  Aminoacyl carrier protein;  A9CHM9          PDB; 2JQ4; NMR; -; A=1-83.
                                    PDB; 4H2W_5GP.pdb; X-ray; 1.95 A; C/D=1-83.
                                    PDB; 4H2X_G5A.pdb; X-ray; 2.15 A; C/D=1-83.
                                    PDB; 4H2Y; X-ray; 2.10 A; C/D=1-83.

To preserve the empty lines remove RS= and add statement {print $0"\n"}:

$ awk -v RS='\n\n' '/...._...\.pdb; NMR;/{print $0"\n"}' infile
$ awk -v RS='\n\n' '/...._...\.pdb; X-ray;/{print $0"\n"}' infile
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.