English 中文(简体)
迅速从档案中删除与索引有关的一条线
原标题:fast deletion of a line with an index from a file
  • 时间:2011-10-28 22:33:30
  •  标签:
  • shell
  • sed
  • awk

我有10国集团的文献。 我想从档案中删除第18888条。

我使用的是:

sed -i  188888d  file

问题确实是缓慢的。 我的理解是,这是因为档案的篇幅,但无论如何,我可以更快地这样做。

增 编

问题回答

Try

sed -i  188888{;d;q;}  file

You may need to experiment with which of the above semi-colons you keep, {d;q} ... being the 2nd thing to try.

这将在删除一条线后停止查找档案,但你仍然不得不花时间重写档案。 还值得测试。

sed  188888{;q;d;}  file > /path/to/alternate/mountpoint/newFile

候补顶点在单独的磁盘上。

final edit Ah, one other option would be to edit the file while it is being written through a pipe

 yourLogFileProducingProgram | sed -i  188888d  > logFile

但是,这假设你知道你想要删除的数据总是符合第1888888条,这是可能的吗?

我希望这一帮助。

The file lines are determined by counting the character, if the line size are variable then you cannot calculate the offset to the location given a line but have to count the number of newlines.

这永远是O(n),在档案中是 n的数量。

平行算法也无助于,因为这种操作是软盘内分光仪有限,分立和组装会更慢。

如果你将在同一档案中做大量的工作,那么就有办法预先处理档案,使之更快。

A easy way is to build a index with

line#:offset

当你想找到一条线时,就你想要的线数而言,进行双轨搜索(Log n),并利用被抵消的线在原始档案中查找。





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签