免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 Shell 求助
最近访问板块 发新帖
查看: 1269 | 回复: 7
打印 上一主题 下一主题

求助 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-07 15:51 |只看该作者 |倒序浏览
Write a shell script (/bin/sh) called 'fileline' which is passed two command line parameters. The first parameter is the name of a file and the second is a number 'n'. The script should write the contents of the nth line of the file to a new file called 'out'. If the input file does not exist or no such line exists in the file, the script should write an error message to the terminal.

高手们 能不能帮我解决一下这个问题啊。小女子在此谢过了

论坛徽章:
0
2 [报告]
发表于 2006-08-07 15:57 |只看该作者
很多脚本的开头都有这个参数检查的,自己搜索一下吧
给你个我谢的一个统计脚本的例子

  1. #!/usr/bin/ksh
  2. (($#!=1))||[[ ! -f $1 ]]&&{ echo "Usage:./$(basename $0)  filename"; exit 1; }
  3. rm caps.tmp>/dev/null 2>/dev/null;
  4. rm cap.tmp>/dev/null 2>/dev/null;
  5. grep TC_BEGIN $1 >cap.tmp
  6. awk   '{gsub(/\[DS1\]/,"|");
  7.         gsub(/ /,"");
  8.         gsub(/\)=/,"|");
  9.         gsub(/-/,"|");
  10.         gsub(/\(/,"|");
  11.         print $0
  12.         }' cap.tmp >caps.tmp
  13. awk -F "|" '{array[i++]=$6;if(i>1){caps=(array[i-1]-array[i-2])/60;print $1,caps}}' caps.tmp
  14. rm caps.tmp
  15. rm cap.tmp
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-08-08 12:54 |只看该作者
bash: ./fileline: /usr/bin/ksh: bad interpreter: No such file or directory
but why I got this information after compile
thanks again

论坛徽章:
0
4 [报告]
发表于 2006-08-08 13:12 |只看该作者
whereis ksh

论坛徽章:
0
5 [报告]
发表于 2006-08-08 14:26 |只看该作者
root@saixu25 /tmp : cat fileline.sh
#!/bin/sh
if [ $# -ne 2 ]
  then
      echo "
usage : fileline.sh filename no_of_line
           "
      exit
fi

if [ -f $1 ]
  then
      sed -n "1,$2p" $1 >$1.out
  else
      echo " $1 not found "
fi

论坛徽章:
0
6 [报告]
发表于 2006-08-08 14:42 |只看该作者
want csh?

论坛徽章:
0
7 [报告]
发表于 2006-08-08 20:29 |只看该作者
ksh

is in the code you gave me in the first line so I though maybe some mistakes. Please help me  to correct them.

论坛徽章:
0
8 [报告]
发表于 2006-08-11 19:35 |只看该作者
大蚂蚁 你给我的代码有点问题 请帮帮忙 谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP