Home > OS >  Linux document editing problems (delete the content of the specific line after)
Linux document editing problems (delete the content of the specific line after)

Time:09-21

The following documents, for example, I want to put the header contains a hypothetical protein entire segment are deleted, how to do? Thank you for your attention!

WP_034790625. 1 LysR family transcriptional regulator [Ensifer adhaerens]
MDLLSAMRSFRRVIELQSFNKAAEELGQSNASISKQVRQLEERLGAVLIVRTTRRMSLSENGRAYFSECCRLLDELDHLE
RTTSGEAGEINGRLRLNAPLSFGLTVLAPMLARFMTLHPQLKVDMTLDDHVLNVVSEGFDVSIRVRAALTDSSLIARRLG

WP_034791832. 1 hypothetical protein [Ensifer adhaerens]
MPNTGGNNESLANRLTAHGREPTDFPDDSPLGKGDLREPREPVPEFDEPDDQDDLDETEEIELESIFDPDRYDPDDDFPP
PG

WP_034796082. 1 crotonase [Ensifer adhaerens]
MSVTFVVEDRVASVTLNRPERMNAVDAATERELDAIWEEIEARDDISCVVLTGAGERAFCAGADLKGAEKTGLDYWTESR
EGVRAFQEKRAPVWRGR

WP_034796116. 1 hypothetical protein [Ensifer adhaerens]
MSGQSETKLKQLLQAVPPGFLVDTAWMARHAISRQSVSGYVKRGWLEPALTGLYRRPFSPDTNPDAVTGWKIPLLSAIWL
DMSAIDLGTGDRALTPGGRLHPAYRITIPDELMPNETPRGA

WP_034796134. 1 glycosyl hydrolase [Ensifer adhaerens]
MDPEEIARSMNGLLQTVSPERMEALLPSPMIQNHAAFLHLLSDGALACAWFGGTLEGKSDISIFASVLPKGATQWGPPQR
MADHLLEVRDLSVEFHTAVGVVKAVRNISYHLDRGETLAILGESGSGKSVSSSAIMNLIDMPPGRISSGEILLDGVDLLP
CLSQDGGKTFPVRLLIEDGPG

WP_034796142. 1 peptide ABC from the substrate - binding protein [Ensifer adhaerens]
MKKLFVLSALMLSSALSPAFAGSGPIKIVLAEEADLLEPCMATRSNIGRVIMQNVSETLTELDVRSDKGVMPRLAEKWEQ
MADHLLEVRDLSVEFHTAVGVVKAVRNISYHLDRGETLAILGESGSGKSVSSSAIMNLIDMPPGRISSGEILLDGVDLLP
FKPTMATNGTLQLSEIKIK

WP_034796160. 1 ABC from ATP binding protein [Ensifer adhaerens]
MADHLLEVRDLSVEFHTAVGVVKAVRNISYHLDRGETLAILGESGSGKSVSSSAIMNLIDMPPGRISSGEILLDGVDLLP
DFADHVMVMQKGNIVELGTVREVFDAPQQDYTRALLAAGLDPDPDVQAAHRAARLQRAS

WP_034796309. 1 hypothetical protein [Ensifer adhaerens]
MNTSLIADSFVSLAALGGLLVLIGVIRSFDAKSPLNRRFLFGLQVLAALMASRVLAWWTDLFIFKAATIITAGLVPLSTV
LLAEGLLRRHAPRNTKWIAAGGAATFFVLAFLPVSLAEPWRVALLFLYQLVTFALAGHMTVTRDRTSLSKAENQAVDRIA

WP_034796322. 1 hypothetical protein [Ensifer adhaerens]
MDNDPFHAGEQQLQSLFAVREQLAGSRAIQASLPPGFAGFLAELHYVVLAVPDREGRIWVTMVFGRPGFLSAPDAMRVRV
GTGEMVVMTGHAVLDGFDGRLRRSHEGMPMNGLVRFKPDLLMSRTALARP

CodePudding user response:

See you as if is 3 lines, each can be used:
Sed -i '/hypothetical protein/, + 3 d' file. TXT delete matching to the hypothetical protein line, and then two lines (3), d is the sed command delete the match to the line, the -i is to modify the original file, do not add the -i, print only, do not change the

Or you're not sure each paragraph is three lines, you is a blank line between each paragraph, so direct matching hypothetical protein to a blank line between lines:
Sed -i '/hypothetical protein/,/^ $/d' file. TXT

CodePudding user response:

reference 1st floor zhouchao6 response:
see you as if is 3 lines, each can be used:
Sed -i '/hypothetical protein/, + 3 d' file. TXT delete matching to the hypothetical protein line, and then two lines (3), d is the sed command delete the match to the line, the -i is to modify the original file, do not add the -i, print only, do not change the

Or you're not sure each paragraph is three lines, you is a blank line between each paragraph, so direct matching hypothetical protein to a blank line between lines:
Sed -i '/hypothetical protein/,/^ $/d' file. TXT
is really thank you! In fact it is not empty lines and then also is not necessarily the three lines, don't know if this is the case?

CodePudding user response:

Then find a rule, write a script to handle

CodePudding user response:

Or no empty lines, you first to add a blank line, and then delete, processing will be a little bit more simple
WP_034796322. 1 hypothetical protein [Ensifer adhaerens] like this is & gt; At the beginning of,
Sed -i 's/^ & gt;/\ n>/'file. TXT all & gt; At the beginning of, replaced by a newline character + & gt;
Sed -i '/hypothetical protein/,/^ $/d' file. TXT and then use the above methods to remove
Sed -i 's/^ $/d' file. TXT finally to add empty lines and delete

This method is a little easier, or write a script to deal with according to the line number, or use the if judgment will have trouble

CodePudding user response:

reference 4 floor zhouchao6 response:
or no empty lines, you first to add a blank line, and then delete, processing will be a little bit more simple
WP_034796322. 1 hypothetical protein [Ensifer adhaerens] like this is & gt; At the beginning of,
Sed -i 's/^ & gt;/\ n>/'file. TXT all & gt; At the beginning of, replaced by a newline character + & gt;
Sed -i '/hypothetical protein/,/^ $/d' file. TXT and then use the above methods to remove
Sed -i 's/^ $/d' file. TXT finally to add empty lines and delete

This method is a simple point, or write a script to deal with according to the line number, or use the if judgment will have trouble
thank you! Problem has been solved, by adding a line to make rule! thank you
  • Related