Home > OS >  The shell how to delete the line between two strings
The shell how to delete the line between two strings

Time:10-29

My file format is as follows, for it is many times the output data in a file, have the same comments section I want to delete this part, the comments section is slightly different, but note the beginning and end of the string, I want to keep only "formal" content, thank you all for the great god
ITEM: TIMESTEP within
.
.
.
ITEM: ATOMS id type vx vy vz

Formal content

ITEM: TIMESTEP within
.
.
.
ITEM: ATOMS id type vx vy vz

Formal content

ITEM: TIMESTEP within
.
.
.
ITEM: ATOMS id type vx vy vz

CodePudding user response:

/root @ localhost ~ # cat a
ITEM: TIMESTEP within
.
.
.
ITEM: ATOMS id type vx vy vz

Formal content

ITEM: TIMESTEP within
.
.
.
ITEM: ATOMS id type vx vy vz

Formal content

ITEM: TIMESTEP within
.
.
.
ITEM: ATOMS id type vx vy vz
/root @ localhost ~ # sed '/TEM: TIMESTEP within/,/ITEM: ATOMS id type vx vy vz/d' a

Formal content


Formal content

CodePudding user response:

If want to direct execution, use sed - I went, the match between the two lines of content, including two lines all deleted, the rest of the still

CodePudding user response:

 

Startlen=` cat/etc/passwd | grep -n 'root: x:' | - d: the cut - f1 `
Endlen=` cat/etc/passwd | grep -n 'SSHD: x:' | - d: the cut - f1 `


Z with sed to remove between the start and end finally, specific command forgot, just learning
  • Related