- 论坛徽章:
- 0
|
本帖最后由 sakulagi 于 2011-07-15 15:35 编辑
試了試,寫個shell script應該還是能實現的:
- #!/bin/bash
- section_found=0;
- if [ "$#" -lt 4 ]
- then
- echo "usage: $0 INPUT_FILE [SECTION_TO_SEARCH] KEY_TO_MODIFY NEW_KEY_VALUE > new_ini_file_name"
- exit
- fi
- cat $1 | while read line; do
- if [[ $line == "$2" ]]
- then
- #echo "section found"
- section_found=1;
- elif [[ $line == \[* ]]
- then
- section_found=0
- elif [[ $line == $3* ]]
- then
- #echo "comment found"
- if [ "$section_found" -eq 1 ]
- then
- line="$3 = $4"
- fi
- fi
- echo $line
- done
复制代码 例子 (假設script叫comment.sh, 你的文件是test.ini)
./comment.sh test.ini [test] comment new_b > new_test.ini
寫的有點麻煩,全黨抛磚引玉了 |
|