# 普通直接替换 [heibanbai@heibanbai01 tmp]$ sed 's/banbai/good/g' test.txt this is a test file, contents: 1. heigood 2. hei good 3. hei-good 4. hei_good # 在要替换的字符串前后加 \<要替换的字符串\> [heibanbai@heibanbai01 tmp]$ sed 's/\<banbai\>/good/g' test.txt this is a test file, contents: 1. heibanbai 2. hei good 3. hei-good 4. hei_banbai # 在要替换的字符串前后加 \b要替换的字符串\b [heibanbai@heibanbai01 tmp]$ sed 's/\bbanbai\b/good/g' test.txt this is a test file, contents: 1. heibanbai 2. hei good 3. hei-good 4. hei_banbai