我想编辑特定文件的文本

Don*_*Bit 0 shell-script text-processing

我想修改配置文件,如下图。作为 shell 脚本我可以做什么?

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "Touch"
        Option  "Calibration"   "166 3939 186 3814"
        Option  "SwapAxes"      "1"
        Option  "InvertX"   "on"
        Option  "InvertY"   "on"
EndSection
Run Code Online (Sandbox Code Playgroud)

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "Touch"
        Option  "Calibration"   "166 3939 186 3814"
        Option  "SwapAxes"      "1"
        Option  "InvertX"   "off"
        Option  "InvertY"   "on"
EndSection
Run Code Online (Sandbox Code Playgroud)

Mic*_*hrs 5

甚至

sed -i '/InvertX/s/"on"/"off"/' file_name
Run Code Online (Sandbox Code Playgroud)

  • 或者,`sed -i '/InvertX/ s/on/off/2' filename` 只将 `on` 的 **second** 出现更改为 `off`。 (2认同)