免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1329 | 回复: 7
打印 上一主题 下一主题

awk问题,在线等,谢谢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-03 17:49 |只看该作者 |倒序浏览
我有一个222.txt文件,文件内容如下
1111111|2222|
2222222|2222|
1213233|1234|
2131231|2345|
想把此文件的第一个字段,和第二个字段的值分别付给如下语句中的
update basetab set accountleft=accountleft+%d where accountnumber=(select accountnumber from bind where number='%s')中的%s和%d处,并且把update语句写入temp.sql中
最后生成update basetab set accountleft=accountleft+2222 where accountnumber=(select accountnumber from bind where number='1111111');
update basetab set accountleft=accountleft+2222 where accountnumber=(select accountnumber from bind where number='2222222');
update basetab set accountleft=accountleft+1234 where accountnumber=(select accountnumber from bind where number='1213233');
update basetab set accountleft=accountleft+2345 where accountnumber=(select accountnumber from bind where number='2131231')
这样的文件,

我写了一个shell,内容如下:
awk -f creatsql.awk 2222.txt>temp.sql
tail temp.sql

其中creatsql.awk 内容如下:
BEGIN{
FS="|"
}
{
printf("update basetab set accountleft=accountleft+%d where accountnumber=(select accountnumber from bind where number='%s');\n",$2,$1)
}

但是执行不成功,请高手执教!谢谢!

论坛徽章:
0
2 [报告]
发表于 2004-06-03 18:11 |只看该作者

awk问题,在线等,谢谢

在SCO环境执行成功,,建议你检查一下是不是有笔误或不可见字符存在

可以把错误信息贴上来吗?

论坛徽章:
0
3 [报告]
发表于 2004-06-03 18:14 |只看该作者

awk问题,在线等,谢谢

我执行了一下没问题啊,你的错误提示是什么?
还有,是不是你没给creatsql.awk加上可执行的属性啊?
我的结果


update basetab set accountleft=accountleft+2222 where accountnumber=(select accunt  number from bind where number='1111111');                                   
update basetab set accountleft=accountleft+2222 where accountnumber=(select accunt  number from bind where number='2222222');                                   
update basetab set accountleft=accountleft+1234 where accountnumber=(select accunt  number from bind where number='1213233');                                   
update basetab set accountleft=accountleft+2345 where accountnumber=(select accunt  number from bind where number='2131231');                                   
           

是要这样的结果吗?

论坛徽章:
0
4 [报告]
发表于 2004-06-03 19:20 |只看该作者

awk问题,在线等,谢谢

错误信息如下:
root@huawei # modify.sh
begin
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 2
awk: illegal statement near line 2
awk: syntax error near line 3
awk: bailing out near line 3
step is finished
root@huawei #
视不是变量不对,我的操作系统solaris 5.7

论坛徽章:
0
5 [报告]
发表于 2004-06-03 19:47 |只看该作者

awk问题,在线等,谢谢

我知道原因了,是我上传文件中有问题,
BEGIN{
FS="|"
}
{
printf("update basetab set accountleft=accountleft+%d where accountnumber=(select accountnumber from bind where number='%s');\n",$2,$1)
}
用vi打开文件后发现BEGIN{^M
FS="|" ^M
}^M
每一行多了^M,不知是何原因?

论坛徽章:
0
6 [报告]
发表于 2004-06-03 19:55 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
7 [报告]
发表于 2004-06-03 19:57 |只看该作者

awk问题,在线等,谢谢

你是从win下传过来的的代码吧?

论坛徽章:
0
8 [报告]
发表于 2004-06-03 20:00 |只看该作者

awk问题,在线等,谢谢

sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
                      #在bash/tcsh中,按下Ctrl-V然后按 Ctrl-M
###注意命令中"^M"在输入时一定是按下Ctrl-V然后按 Ctrl-M
###如果输入成ctrl+6键,然后输入一个大写M,什么替换也完成不了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP