Skip to main content
2 of 2
fix 'sed' part of command after reading comments
Httqm
  • 1.2k
  • 8
  • 17

As a one-liner to demonstrate the concept :

echo -e 'a\nb\nc\nPATTERN\nd\ne\nf' | sed '0,/PATTERN/ s/^/#/' 

You just have to adapt to your context :

  • as for the 'PATTERN'
  • I assumed '#' as the commenting character
  • and regarding how you can apply this to all your files. If they all are 'fileXXX.txt', you can run : sed -i '0,/PATTERN/ s/^/#/' file*txt
Httqm
  • 1.2k
  • 8
  • 17