Home > Blockchain >  Delete ALL Regex Matched Line
Delete ALL Regex Matched Line

Time:04-14

this is my file:

remark goes here
MASS
Pd 0.000         0.000               ATTN, need revision
ns 14.010        0.530               same as n  

BOND
Pd-cl    0.00   0.000       ATTN, need revision
Pd-na    0.00   0.000       ATTN, need revision
c -ns  427.60   1.379       same as c -n 
ns-hn  403.20   1.013       same as hn-n 
ns-c3  328.70   1.462       same as c3-n 

ANGLE
Pd-na-c2    0.000       0.000   ATTN, need revision
Pd-na-cc    0.000       0.000   same as Pd-na-c2
cl-Pd-na    0.000       0.000   ATTN, need revision
cl-Pd-cl    0.000       0.000   ATTN, need revision
na-Pd-na    0.000       0.000   ATTN, need revision
c2-c -ns   69.957     115.170   Calculated with empirical approach
cc-c2-c    67.710     120.700   same as c -c2-c2
c -ns-hn   48.330     117.550   same as c -n -hn
c -ns-c3   63.390     120.690   same as c -n -c3
o -c -ns   74.220     123.050   same as n -c -o 
ns-c3-h1   49.840     108.880   same as h1-c3-n 
hn-ns-c3   45.800     117.680   same as c3-n -hn

DIHE
cl-Pd-na-c2   1    0.000         0.000           0.000      ATTN, need revision
cl-Pd-na-cc   1     -nan         0.000           0.000      same as cl-Pd-na-c2
na-Pd-na-c2   1    0.000         0.000           0.000      ATTN, need revision
na-Pd-na-cc   1    0.000         0.000           0.000      ATTN, need revision
c2-c2-cc-ha   1    6.650       180.000           2.000      same as X -c2-ce-X 
c2-c2-cc-cd   1    6.650       180.000           2.000      same as X -c2-ce-X 
c2-c -ns-hn   1    2.500       180.000           2.000      same as X -c -n -X 
c2-c -ns-c3   1    2.500       180.000           2.000      same as X -c -n -X 
ha-cc-c2-c    1    6.650       180.000           2.000      same as X -c2-ce-X 
cd-cc-c2-c    1    6.650       180.000           2.000      same as X -c2-ce-X 
c -ns-c3-h1   1    0.000         0.000           2.000      same as X -c3-n -X 
o -c -ns-hn   1    2.500       180.000          -2.000      same as hn-n -c -o 
o -c -ns-hn   1    2.000         0.000           1.000      same as hn-n -c -o 
o -c -ns-c3   1    2.500       180.000           2.000      same as X -c -n -X 
hn-ns-c3-h1   1    0.000         0.000           2.000      same as X -c3-n -X 

IMPROPER
Pd-c2-na-cc         1.1          180.0         2.0          Using default value
c2-h4-c2-na         1.1          180.0         2.0          Using default value
c -c2-c2-cc         1.1          180.0         2.0          Using default value
c2-cd-cc-ha         1.1          180.0         2.0          Using default value
cc-cc-cd-ha         1.1          180.0         2.0          Using default value
cd-h4-cc-na         1.1          180.0         2.0          Using default value
c2-ns-c -o         10.5          180.0         2.0          General improper torsional angle (2 general atom types)
c -c3-ns-hn         1.1          180.0         2.0          Using default value

NONBON
  Pd          0.0000  0.0000             ATTN, need revision
  ns          1.8240  0.1700             same as n  

In this file I want to delete all line that contains "ATTN, need revision" line and "0.000 same as" (between same as and 0.000 there may be from 2 to 10 space char 0.000 {2,10} same as ) I applied this command which was successfull:

 sed -i '/ATTN, need revision/d' check2.dat

Then I need to delete this line with match too: 0.000 {2,10} same as

I applied this code but it didn't work: sed -i.old '/0.000 {2,10} same as /d' check2.dat How can I do it? or where am i doing mistake?

Thanks..

My aim Final file is here:

remark goes here
MASS
ns 14.010        0.530               same as n  

BOND
c -ns  427.60   1.379       same as c -n 
ns-hn  403.20   1.013       same as hn-n 
ns-c3  328.70   1.462       same as c3-n 

ANGLE
c2-c -ns   69.957     115.170   Calculated with empirical approach
cc-c2-c    67.710     120.700   same as c -c2-c2
c -ns-hn   48.330     117.550   same as c -n -hn
c -ns-c3   63.390     120.690   same as c -n -c3
o -c -ns   74.220     123.050   same as n -c -o 
ns-c3-h1   49.840     108.880   same as h1-c3-n 
hn-ns-c3   45.800     117.680   same as c3-n -hn

DIHE
c2-c2-cc-ha   1    6.650       180.000           2.000      same as X -c2-ce-X 
c2-c2-cc-cd   1    6.650       180.000           2.000      same as X -c2-ce-X 
c2-c -ns-hn   1    2.500       180.000           2.000      same as X -c -n -X 
c2-c -ns-c3   1    2.500       180.000           2.000      same as X -c -n -X 
ha-cc-c2-c    1    6.650       180.000           2.000      same as X -c2-ce-X 
cd-cc-c2-c    1    6.650       180.000           2.000      same as X -c2-ce-X 
c -ns-c3-h1   1    0.000         0.000           2.000      same as X -c3-n -X 
o -c -ns-hn   1    2.500       180.000          -2.000      same as hn-n -c -o 
o -c -ns-hn   1    2.000         0.000           1.000      same as hn-n -c -o 
o -c -ns-c3   1    2.500       180.000           2.000      same as X -c -n -X 
hn-ns-c3-h1   1    0.000         0.000           2.000      same as X -c3-n -X 

IMPROPER
Pd-c2-na-cc         1.1          180.0         2.0          Using default value
c2-h4-c2-na         1.1          180.0         2.0          Using default value
c -c2-c2-cc         1.1          180.0         2.0          Using default value
c2-cd-cc-ha         1.1          180.0         2.0          Using default value
cc-cc-cd-ha         1.1          180.0         2.0          Using default value
cd-h4-cc-na         1.1          180.0         2.0          Using default value
c2-ns-c -o         10.5          180.0         2.0          General improper torsional angle (2 general atom types)
c -c3-ns-hn         1.1          180.0         2.0          Using default value

NONBON
  ns          1.8240  0.1700             same as n  

CodePudding user response:

With GNU sed, you can use

sed -E -i '/ATTN, need revision|0\.000[[:blank:]] same as/d' check2.dat
sed -E -i '/ATTN, need revision|\<0\.000[[:blank:]] same as/d' check2.dat

See the online demo:

#!/bin/bash
s='Pd-na-c2    0.000       0.000   ATTN, need revision
Pd-na-cc    0.000       0.000   same as Pd-na-c2
cl-Pd-na    0.000       0.000   ATTN, need revision
cl-Pd-cl    0.000       0.000   ATTN, need revision
na-Pd-na    0.000       0.000   ATTN, need revision
c2-c -ns   69.957     115.170   Calculated with empirical approach'
sed -E '/ATTN, need revision|0\.000[[:blank:]] same as/d' <<< "$s"
## => c2-c -ns   69.957     115.170   Calculated with empirical approach

The POSIX ERE regex matches

  • ATTN, need revision - a fixed string
  • | - or
  • \< - a left-hand word boundary
  • 0\.000 - 0.000
  • [[:blank:]] - one or more horizontal whitespaces
  • same as - a fixed string.
  • Related