Skip to main content
added 118 characters in body
Source Link
Dani_l
  • 5.2k
  • 2
  • 21
  • 34

sed seems like the right tool:

sed -i '/radius-server/!b;n;n;d' filename 

How it works:

/radius-server/!b # as long as it's NOT 'radius-server' do nothing (branch to end) n # read next line (replace current line with next line) n # same as above - we now read 2 lines d # delete the current line 

UPDATE - to modify multiple files, simply use glob instead of filename, e.g.

sed -i '/radius-server/!b;n;n;d' * 

sed seems like the right tool:

sed -i '/radius-server/!b;n;n;d' filename 

How it works:

/radius-server/!b # as long as it's NOT 'radius-server' do nothing (branch to end) n # read next line (replace current line with next line) n # same as above - we now read 2 lines d # delete the current line 

sed seems like the right tool:

sed -i '/radius-server/!b;n;n;d' filename 

How it works:

/radius-server/!b # as long as it's NOT 'radius-server' do nothing (branch to end) n # read next line (replace current line with next line) n # same as above - we now read 2 lines d # delete the current line 

UPDATE - to modify multiple files, simply use glob instead of filename, e.g.

sed -i '/radius-server/!b;n;n;d' * 
Source Link
Dani_l
  • 5.2k
  • 2
  • 21
  • 34

sed seems like the right tool:

sed -i '/radius-server/!b;n;n;d' filename 

How it works:

/radius-server/!b # as long as it's NOT 'radius-server' do nothing (branch to end) n # read next line (replace current line with next line) n # same as above - we now read 2 lines d # delete the current line