免费注册 查看新帖 |

Chinaunix

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

如何删除文本文件的最后一行?要求效率最高. [复制链接]

论坛徽章:
0
31 [报告]
发表于 2009-05-26 22:04 |只看该作者
原帖由 r2007 于 2009-5-22 16:37 发表
罗嗦点儿
dd of=urfile seek=1 bs=$(($(find urfile -printf "%s"-$(tail -1 urfile|wc -c)))
or
dd of=urfile seek=1 bs=$(($(stat -c%s urfile)-$(tail -1 urfile|wc -c)))


大侠,解释一下吧,
输入文件呢?
dd of=urfile seek=1 bs=...,
感觉就没有输入文件啊
谢谢

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
32 [报告]
发表于 2009-05-26 22:12 |只看该作者

回复 #31 xnkjdx1998 的帖子

:的输出就是输入文件。

只是truncate了of.

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
33 [报告]
发表于 2009-05-26 22:23 |只看该作者

回复 #31 xnkjdx1998 的帖子

manpage of dd

`of=FILE'
     output file : Write to FILE instead of standard output.  Unless `conv=notrunc'
     is given, `dd' truncates FILE to zero bytes (or the size specified
     with `seek=').

论坛徽章:
0
34 [报告]
发表于 2009-05-27 00:03 |只看该作者
原帖由 blackold 于 2009-5-25 18:20 发表
是:命令,shell内置命令。你晕了。


     :     No effect; the command does nothing. A zero exit  code
           is returned.

这个吗?

论坛徽章:
0
35 [报告]
发表于 2009-05-27 00:22 |只看该作者
貌似明白了些:

     of=file
           Specifies the output  path.  Standard  output  is  the
           default.  If  the  seek=expr  conversion  is  not also
           specified, the output file will  be  truncated  before
           the  copy begins, unless conv=notrunc is specified. If
           seek=expr is specified, but conv=notrunc is  not,  the
           effect  of  the copy will be to preserve the blocks in
           the output file over which dd seeks, but no other por-
           tion  of  the  output  file will be preserved. (If the
           size of the seek plus the size of the  input  file  is
           less  than  the  previous size of the output file, the
           output file is shortened by the copy.)

就是指直接在原文件上做改动,是不是这个意思?

论坛徽章:
2
申猴
日期:2013-12-26 22:11:31天秤座
日期:2014-12-23 10:23:19
36 [报告]
发表于 2009-05-27 07:32 |只看该作者
c语言的话可以直接lseek

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
37 [报告]
发表于 2009-05-27 08:49 |只看该作者

回复 #34 welcome008 的帖子

对。

论坛徽章:
0
38 [报告]
发表于 2009-05-27 08:54 |只看该作者
学习了,谢谢

论坛徽章:
0
39 [报告]
发表于 2009-05-27 11:49 |只看该作者
原帖由 r2007 于 2009-5-22 16:37 发表
罗嗦点儿
dd of=urfile seek=1 bs=$(($(find urfile -printf "%s"-$(tail -1 urfile|wc -c)))
or
dd of=urfile seek=1 bs=$(($(stat -c%s urfile)-$(tail -1 urfile|wc -c)))



高人都隐藏在市井之中。。。学无止境!!!

论坛徽章:
1
巨蟹座
日期:2013-12-30 17:06:34
40 [报告]
发表于 2009-05-27 11:54 |只看该作者
mark.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP