/********************************************************************************* * Linux sed 替換第一次出現的字符串 * 說明: * 需要替換配置文件中第一次出現的文本內容。 * * 2016-12-16 深圳 南山平山村 曾劍鋒 ********************************************************************************/ 一、參考文檔: How to use sed to replace only the first occurrence in a file? http://stackoverflow.com/questions/148451/how-to-use-sed-to-replace-only-the-first-occurrence-in-a-file 二、測試代碼: sed -i '0,/IP = .*/s/IP = .*/IP = 10.10.10.10/' /usr/share/config.conf