sed '/^#/!s/test/TEST/g' /path/to/infile
Output
$ sed '/^#/!s/test/TEST/g' infile
TEST
# test
# test
TEST
*Note: If your only requirement for a comment is that the very first non-whitespace character is a #
, then you can use:
sed '/^[[:space:]]*#/!s/test/TEST/g' /path/to/infile
Output
$ sed '/^[[:space:]]*#/!s/test/TEST/g' infile
TEST
# test
# test
TEST
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…