0

I am having a file that looks like this:

PEBP1_HUMAN Homo sapiens    P30086  PDB; 1BD9; X-ray; 2.05 A; A/B=1-187.
                    PDB; 1BEH; X-ray; 1.75 A; A/B=1-187.
                    PDB; 2L7W; NMR; -; A=1-187.
                    PDB; 2QYQ; X-ray; 1.95 A; A=1-187.

PECA1_HUMAN Homo sapiens    P16284  PDB; 2KY5; NMR; -; A=686-738.
                    PDB; 5C14; X-ray; 2.80 A; A/B=28-229.
                    PDB; 5GEM; X-ray; 3.01 A; A/B=28-232.

PELO_HUMAN  Homo sapiens    Q9BRX2  PDB; 1X52; NMR; -; A=261-371.
                    PDB; 5EO3; X-ray; 2.60 A; A/B=265-385.
                    PDB; 5LZW; EM; 3.53 A; ii=1-385.
                    PDB; 5LZX; EM; 3.67 A; ii=1-385.
                    PDB; 5LZY; EM; 3.99 A; ii=1-385.
                    PDB; 5LZZ; EM; 3.47 A; ii=1-385.

From this file I want to match all EM; elements that are found just after PDB; (four letter code); EM;. So under this column either X-ray;, NMR; or EM; can be found. For those lines that have EM; remove them. Is there some bash command that I can use to match these elements and remove these lines?

Importantly when matching it put the space before EM, so match it with space, like EM;.

Expected result is:

PEBP1_HUMAN Homo sapiens    P30086  PDB; 1BD9; X-ray; 2.05 A; A/B=1-187.
                    PDB; 1BEH; X-ray; 1.75 A; A/B=1-187.
                    PDB; 2L7W; NMR; -; A=1-187.
                    PDB; 2QYQ; X-ray; 1.95 A; A=1-187.

PECA1_HUMAN Homo sapiens    P16284  PDB; 2KY5; NMR; -; A=686-738.
                    PDB; 5C14; X-ray; 2.80 A; A/B=28-229.
                    PDB; 5GEM; X-ray; 3.01 A; A/B=28-232.

PELO_HUMAN  Homo sapiens    Q9BRX2  PDB; 1X52; NMR; -; A=261-371.
                    PDB; 5EO3; X-ray; 2.60 A; A/B=265-385.
1

awk can do that:

awk '{if(!($1=="PDB;"&&$3=="EM;")){print}}' <yourfile

This tests if the first column (by default whitespaces are taken as the delimiter) of the current line is PDB; and the third column is EM; and prints the line only if not both are true.

Output

$ awk '{if(!($1=="PDB;"&&$3=="EM;")){print}}' <test
PEBP1_HUMAN Homo sapiens    P30086  PDB; 1BD9; X-ray; 2.05 A; A/B=1-187.
                    PDB; 1BEH; X-ray; 1.75 A; A/B=1-187.
                    PDB; 2L7W; NMR; -; A=1-187.
                    PDB; 2QYQ; X-ray; 1.95 A; A=1-187.

PECA1_HUMAN Homo sapiens    P16284  PDB; 2KY5; NMR; -; A=686-738.
                    PDB; 5C14; X-ray; 2.80 A; A/B=28-229.
                    PDB; 5GEM; X-ray; 3.01 A; A/B=28-232.

PELO_HUMAN  Homo sapiens    Q9BRX2  PDB; 1X52; NMR; -; A=261-371.
                    PDB; 5EO3; X-ray; 2.60 A; A/B=265-385.
1

You could do something like this - using perl's paragraph mode:

$ perl -F'\n' -00le 'print join "\n", grep { !/PDB; ....; EM;/ } @F' file
PEBP1_HUMAN Homo sapiens    P30086  PDB; 1BD9; X-ray; 2.05 A; A/B=1-187.
                    PDB; 1BEH; X-ray; 1.75 A; A/B=1-187.
                    PDB; 2L7W; NMR; -; A=1-187.
                    PDB; 2QYQ; X-ray; 1.95 A; A=1-187.

PECA1_HUMAN Homo sapiens    P16284  PDB; 2KY5; NMR; -; A=686-738.
                    PDB; 5C14; X-ray; 2.80 A; A/B=28-229.
                    PDB; 5GEM; X-ray; 3.01 A; A/B=28-232.

PELO_HUMAN  Homo sapiens    Q9BRX2  PDB; 1X52; NMR; -; A=261-371.
                    PDB; 5EO3; X-ray; 2.60 A; A/B=265-385.

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.