求助 shell删除文档里的指定行
时间:2011-05-10
来源:互联网
怎么删除 文档中的制定行
例如 test文档中有
1 Mary;xxxx;1377777777
2 Harry;xxxx;138888888
3 Barry;xxxx;139999999
根据关键字 比如Harry 删除文档 第二行
test文档变成
1 Mary;xxxx;1377777777
2 Barry;xxxx;139999999
作者: hanxu588 发布时间: 2011-05-10
作者: shplpy 发布时间: 2011-05-10
- $ grep -Fv Harry urfile
- $ sed '/Harry/d' urfile
- $ awk '!/Harry/' urfile
作者: blackold 发布时间: 2011-05-10
我不会啊 不知道怎么写 只会用awk grep写
我知道这样很费劲 但是没办法 写不出来
作者: hanxu588 发布时间: 2011-05-10
晕
前提要求就是 不能用 grep awk sed 来写
作者: hanxu588 发布时间: 2011-05-10
我不会啊 不知道怎么写 只会用awk grep写
我知道这样很费劲 但是没办法 写不出来
hanxu588 发表于 2011-05-10 09:08
直接在文件中删除似乎不行,只能是把你想要的文本重新输出到新的文件
作者: shplpy 发布时间: 2011-05-10
我也是这么想的 就想 问问有没有更简单的方法
暂时 没写出来
初学shell 有很多不懂的 多谢了
作者: hanxu588 发布时间: 2011-05-10
作者: shplpy 发布时间: 2011-05-10
我晕,
可以要用什么工具?

作者: blackold 发布时间: 2011-05-10
就是最基本的shell语言 不能用任何tools
应为用awk sed grep很简单 所以......
作者: hanxu588 发布时间: 2011-05-10
没有啊 我只是在写一个 shell作业
对你们来说应该是 很简单的作业
教授有很多限制 所以 不是很好写
作者: hanxu588 发布时间: 2011-05-10
那就用纯shell实现。
作者: blackold 发布时间: 2011-05-10
恩 你会吗 我想的很麻烦 所以 想写的简单的
作者: hanxu588 发布时间: 2011-05-10
- cat file4.txt |while read line ;do line=`echo $line|cut -d" " -f2|cut -d";" -f1`;[ "$line" != "Harry" ] && echo "$line" ; done
简单的方法你都不让用了,只能用麻烦的了
作者: dzhxc 发布时间: 2011-05-10
- while read line;do if [[ ! ($line =~ Harry ) ]];then echo "$line";fi;done <urfile
作者: blackold 发布时间: 2011-05-10
cat 和 cut 可以用吗
你看我作业要求
Implement in shell a "telephone book" program, which works according to the description given below (lines starting with "--" are comments, user inputs are in bold face, programs responses are in lower case. In the actual execution, user commands can be in lower/upper case). Note: do not use tools such as sed or awk, only standard shell.
作者: hanxu588 发布时间: 2011-05-10
bash 不可以
这个 试过了 不行
作者: hanxu588 发布时间: 2011-05-10
也不能用bash吗?
作者: blackold 发布时间: 2011-05-10
Implement in shell a "telephone book" program, which works according to the description given below (lines starting with "--" are comments, user inputs are in bold face, programs responses are in lower case. In the actual execution, user commands can be in lower/upper case). Note: do not use tools such as sed or awk, only standard shell.
这是我的作业要求 应该不可以用bash
作者: hanxu588 发布时间: 2011-05-10
作者: blackold 发布时间: 2011-05-10
回复 hanxu588
这作业里说的很明确啊,awk sed 不可以用,但是grep没有提到。可以用grep啊,还要求区分大小写。
如果真的不让用grep,至少cat和cut这些都是所谓的 标准shell命令……
要是cat和cut都不可以用,那你们老师可以去专门写个shell了
作者: dzhxc 发布时间: 2011-05-10
就是写一个类似电话本的东西
可以添加 删除 用户 等等
我都写完了 就剩一个 删除 不知道怎么删除
#!/bin/sh
不能用 shell工具 例如sed awk 去删除保存在文档中的用户 只能用最基本的shell
作者: hanxu588 发布时间: 2011-05-10
用黑哥写的吧
这里面真的是纯shell……
作者: dzhxc 发布时间: 2011-05-10
这个不懂了。
作者: blackold 发布时间: 2011-05-10
没 你理解错了
是不能用shell 工具 例如awk 和 sed, 只能用最基本的shell来写
作者: hanxu588 发布时间: 2011-05-10
cat 和 cut 倒是是shell的tools 还是包含在最基础的shell 命令那
我很 困惑
例如cp rm alias 都是shell 最基本的指令 awk sed 不是
作者: hanxu588 发布时间: 2011-05-10
你看不懂中文吗?人家要求只能用shell,不能用bash。
作者: blackold 发布时间: 2011-05-10
看懂了,这种要求简直是无理取闹啊
作者: dzhxc 发布时间: 2011-05-10
这个无语了
老师一牛逼 出的题目 都不同凡响
郁闷
作者: hanxu588 发布时间: 2011-05-10
作者: blackold 发布时间: 2011-05-10
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28