免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: stranger88
打印 上一主题 下一主题

如何通过shell脚本替换文件特定内容 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-02-10 13:04 |只看该作者
原帖由 我是DBA 于 2009-2-10 12:56 发表
不错,学习一下shift 2的用法


讲一下shift 2的用法吧

论坛徽章:
0
12 [报告]
发表于 2009-02-10 13:12 |只看该作者
原帖由 ynchnluiti 于 2009-2-10 12:03 发表

是后面加个Data吧


首先谢谢各位了!

真是抱歉,表述的不准确!



下面补充一下:

eg。 修改InputDevice 中的MinX,MinY,MaxX,MaxY对应的数字。
#xxx.sh  MinXData MinYData MaxXData MaxYData
即:
#xxx.sh 50 100 50 100

『修改前』:
Section "InputDevice"
    Identifier  "IDCTouchScreen"
    Driver      "idctouch"
    Option      "Device" "/dev/psaux"
    Option      "Interface" "2"
    Option      "DeviceName" "IDCTouchScreen"
    Option      "MinX" "160"
    Option      "MinY" "235"
    Option      "MaxX" "7898"
    Option      "MaxY" "7700"

    Option      "ScreenNumber"  "0"
    Option      "ButtonNumber"  "2"
    Option      "ReportingMode" "Raw"
    Option      "Emulate3Buttons"   "0"
    Option      "DebugLevel"    "0"
    Option      "SendCoreEvents" "On"
    Option      "RealLeftBtn" "0"
    Option      "WaitDeviceCount1" "100"
    Option      "WaitDeviceCount2" "10"
EndSection
『修改后』
Section "InputDevice"
    Identifier  "IDCTouchScreen"
    Driver      "idctouch"
    Option      "Device" "/dev/psaux"
    Option      "Interface" "2"
    Option      "DeviceName" "IDCTouchScreen"
    Option      "MinX" "50"
    Option      "MinY" "100"
    Option      "MaxX" "50"
    Option      "MaxY" "100"

    Option      "ScreenNumber"  "0"
    Option      "ButtonNumber"  "2"
    Option      "ReportingMode" "Raw"
    Option      "Emulate3Buttons"   "0"
    Option      "DebugLevel"    "0"
    Option      "SendCoreEvents" "On"
    Option      "RealLeftBtn" "0"
    Option      "WaitDeviceCount1" "100"
    Option      "WaitDeviceCount2" "10"
EndSection

论坛徽章:
0
13 [报告]
发表于 2009-02-10 13:36 |只看该作者

回复 #11 yingweixu 的帖子

shift [n]
              The positional parameters from n+1 ... are renamed to  $1  ....
              Parameters  represented  by  the  numbers $# down to $#-n+1 are
              unset.  n must be a non-negative number less than or  equal  to
              $#.   If n is 0, no parameters are changed.  If n is not given,
              it is assumed to be 1.  If n is greater than $#, the positional
              parameters  are not changed.  The return status is greater than
              zero if n is greater than $# or less than zero; otherwise 0.

论坛徽章:
0
14 [报告]
发表于 2009-02-10 13:36 |只看该作者
就用6#的吧,用的时候打多几个词,但也可以改其它参数的

论坛徽章:
0
15 [报告]
发表于 2009-02-26 09:18 |只看该作者

回复 #12 stranger88 的帖子

  1. awk -v v1=50 -v v2=100 '$0~/Section "InputDevice"/{flag="T"}flag=="T"{if($2=="\"MinX\"")$3="\""v1"\"";if($2=="\"MinY\"")$3="\""v2"\"";if($2=="\"MaxX\"")$3="\""v1"\"";if($2=="\"MaxY\""){$3="\""v2"\"";flag="F"}}1' file
复制代码

论坛徽章:
0
16 [报告]
发表于 2009-02-26 10:50 |只看该作者
cat x.sh:
awk '
BEGIN{FS=OFS="\"";ARGC=2}
/"MinX"/{$4=ARGV[2]}
/"MinY"/{$4=ARGV[3]}
/"MaxX"/{$4=ARGV[4]}
/"MaxY"/{$4=ARGV[5]}
{print}' file $*

论坛徽章:
0
17 [报告]
发表于 2009-02-26 12:24 |只看该作者
学习学习!

论坛徽章:
0
18 [报告]
发表于 2009-02-26 15:02 |只看该作者
学习学习!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP