Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment out N lines with sed/awk

Tags:

sed

awk

How can I comment out lines from a certain pattern and N lines onwards?

int var1;
int var2;
int var3;
int var4;
int var5;

I want to comment out 3 lines including var2 (and not according to their content!):

int var1;
// int var2;
// int var3;
// int var4;
int var5;
like image 996
lk. Avatar asked Feb 27 '23 23:02

lk.


1 Answers

This requires GNU sed

sed '/^int var2;$/,+2 s.^.//.'
like image 142
Dennis Williamson Avatar answered Apr 27 '23 22:04

Dennis Williamson