阅读直到线474从文件编号; ñ [英] Read numbers from file until line < n

查看:84
本文介绍了阅读直到线474从文件编号; ñ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我很震惊,我无法找到这个在任何地方,而我的bash技能仍然是低于标准杆。

我素数的文本文件:


  

2 \\ n结果
  3 \\ n结果
  5 \\ n结果
  7 \\ n结果
  11 \\ n结果
  等等...


我要拉下2 ^ 32(4294967296)的加上一个额外的素数所有素数,而这些素数保存到自己的文本文件格式相同的方式。另外,我的文件刚刚超过13十亿行至今,所以限制后停止将是理想的。

更新:问题

在bash脚本已通过循环很长一段时间,这些11个数字无我注意到:


  

4232004449结果
  4232004479结果
  4232004493结果
  4232004509结果
  4232004527结果
  4232004533结果
  4232004559结果
  4232004589结果
  4232004593结果
  4232004613结果
  004437


什么是更加古怪的是我grepped primes.txt(原件),并无处可寻^ 004437。这是某种形式的bash的限制?

更新:解决方案

这似乎是某种东西的限制,我真的不知道是什么。我重新艇员选拔Perl脚本作为我的答案,因为它不仅工作,但它从没有在〜80秒创建〜2GB和包含额外的素数。 <一href=\"http://unix.stackexchange.com/questions/33170/bash-scripting-and-large-files-bug-input-with-the-read-builtin-from-a-redirec\">Go这里解决bash的错误。


解决方案

  $ perl的-lne'打印;最后,如​​果$ _&GT; 2 ** 32'&LT; myprimes.txt&GT; myprimes2.txt

使你输入串联素数高达一素过去2 ** 32,然后停止。不读取源文件到内存中。

As shocked as I am, I can't find this anywhere, and my bash skills are still sub-par.

I have a text file of prime numbers:

2\n
3\n
5\n
7\n
11\n
etc...

I want to pull all primes under 2^32 (4294967296) plus one additional prime number, and save these primes to the own text file formatted the same way. Also, my file has just over 1.3 billion lines so far, so stopping after the limit would be ideal.

Update: Problem.

The bash script has been looping through these 11 numbers for quite some time without me noticing:

4232004449
4232004479
4232004493
4232004509
4232004527
4232004533
4232004559
4232004589
4232004593
4232004613
004437

What's even weirder is I grepped primes.txt (the original) and "^004437" was nowhere to be found. Is this some kind of limitation of bash?

Update: Solution

It appears to be some kind of limitation of something, I really don't know what. I'm re-chosing the perl script as my answer because not only did it work, but it created the ~2GB from nothing in ~80 seconds and included the additional prime. Go here for a solution to the bash error.

解决方案

$  perl -lne 'print; last if $_ > 2**32' < myprimes.txt > myprimes2.txt

Gives you the input series of primes up to one prime past 2**32, then stops. Does not read source file into memory.

这篇关于阅读直到线474从文件编号; ñ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆