首页 \ 问答 \ 使用另一个字符串搜索80 GB文本文件,并将每个字符串的结果保存到单独的文件中(Search an 80 GB text file using strings in another and save the results for each string to separate files)

使用另一个字符串搜索80 GB文本文件,并将每个字符串的结果保存到单独的文件中(Search an 80 GB text file using strings in another and save the results for each string to separate files)

我有一个巨大的80 GB文件,我需要使用另一个较小的文本文件中的字符串进行搜索(这里是踢球者)我需要将每个匹配行的结果保存到用搜索字符串命名的单独文件中。

使用PHP或AWK处理此任务的最有效方法是什么?

示例行:

原始80 GB文本文件:

line1 "value001","value002","Value003"
line2 "Value004","Value005","Value006","Value007"
line3 "value001","value002","Value003"
line4 "value001","value002","Value003"
line5 "value001","value002","Value003"
line6 "Value004","Value005","Value006","Value007"
line7 "value010","value022","Value009"

搜索字符串文本文件search.txt包含以下值:

Value003
Value007
Value009

将生成三个文本文件,其中包含每个搜索字符串的所有匹配行:

Value003.txt would contain lines 1, 3, 4, 5
Value007.txt would contain lines 2 and 6
Value009.txt would contain line 7

补充说明:确切地说,字符串是域名和电话号码列表,如:

joes.com
brick.net
moes.com
sams.net 
2125551212 
2025551212
(202)555-1212

目前,我正在使用textpad中的长正则表达式字符串进行搜索,如下所示:

brick.net|joes.com|moes.com|sams.net|2125551212|2025551212|(202)555-1212

这种搜索既繁琐又缓慢,并导致相当多的误报,如“sams network”和“yellow brick network”。

我试图捕获像sam@sam.net但不是“sams network”的现场值。


I have a massive 80 GB file that I need to search using strings in another smaller text file and (here is the kicker) I need to then save the results for each matching line to separate files named with the search string.

What would be the most efficient way to handle this task with PHP or AWK?

Example lines:

Original 80 GB text file:

line1 "value001","value002","Value003"
line2 "Value004","Value005","Value006","Value007"
line3 "value001","value002","Value003"
line4 "value001","value002","Value003"
line5 "value001","value002","Value003"
line6 "Value004","Value005","Value006","Value007"
line7 "value010","value022","Value009"

Search string text file search.txt contains these values:

Value003
Value007
Value009

Three text files would result containing all the matching lines for each search string:

Value003.txt would contain lines 1, 3, 4, 5
Value007.txt would contain lines 2 and 6
Value009.txt would contain line 7

Additional clarification: To be exact the strings are lists of domains and phone numbers like:

joes.com
brick.net
moes.com
sams.net 
2125551212 
2025551212
(202)555-1212

Currently, I am doing the search using a long regex string in textpad like this:

brick.net|joes.com|moes.com|sams.net|2125551212|2025551212|(202)555-1212

That search is both cumbersome, slow, and results in a fair amount of false positives like "sams network" and "yellow brick network".

I am trying to capture fielded values like sam@sam.net but not "sams network".


原文:https://stackoverflow.com/questions/35882352
更新时间:2022-03-18 11:03

最满意答案

java.lang包中的所有内容都是隐式导入的,您自己不需要这样做。 此POST中的更多详细信息


Everything in the java.lang package is implicitly imported and you do not need to do so yourself. more details in this POST

相关问答

更多
  • 适合所发生情况描述的场景是当您在第一行输入数字时,其余行是框的字符串。 但是nextInt()方法不会超过第一个换行符,所以第一次调用nextLine() ,它会匹配该行的其余部分,直到第一个换行符"" (非null )。 在调用nextInt() ,在for循环之前插入对newLine()的调用以绕过第一个换行符。 String firstNewLine = in.nextLine(); for(int a=0; a <= boxes.length - 1; a++){ The scenario fit ...
  • 将library(foo)放在.Rprofile文件中或设置R_DEFAULT_PACKAGES :请参阅?Rprofile ... 特别是(因为?Rprofile很长,潜在的恐吓): 如果您希望在启动时使用与默认程序包不同的程序包,请在'.Rprofile'或'Rprofile.site'文件中插入“options”的调用。 例如,'options(defaultPackages = character())'在启动时不会附加额外的包(只有'base'包)(或者在运行R之前将'R_DEFAULT_PACK ...
  • 如果我没有弄错的话,当我做你做的事情时: import com.tiemens.secretshare.main.cli.*; public class Foo { } 然后尝试使用javac Foo.java进行编译,我得到: Error:(2, 1) java: package com.tiemens.secretshare.main.cli does not exist 这意味着当编译器javac尝试编译您的类( Shamir.java )时,它需要com.tiemens.secretshare ...
  • java.lang包中的所有内容都是隐式导入的,您自己不需要这样做。 此POST中的更多详细信息 Everything in the java.lang package is implicitly imported and you do not need to do so yourself. more details in this POST
  • 您可以使用javap来检查会发生什么。 示例类: import java.util.ArrayList; public class A { public static void main(String[] args) throws Exception { System.out.println("Test"); } } 编译该类并稍后运行javap -v A - 没有区别,未使用的导入对该类没有影响。 You can use javap to check what happ ...
  • 是的JVM主要是用C和C ++编写的。 不同之处不在于JVM如何处理它,而是程序员如何用C和Java编写代码。 在java中,编码器不需要知道与如何处理内存操作有关的问题(例如,你现在不需要分配多少空间,当你需要知道C时,你不需要处理aritmethic on指针)。 垃圾收集在Java中为您做的是由程序员在C(和C ++)中手动完成的。 这并不意味着java优于C ++。 它只意味着程序员对内存的处理方式不同。 这里列出了两种解决方案的Pro和Cons: 易于开发(Pro Java,Cons C ++) ...
  • 我通过使用名为Resharper的IDE插件修复了这个问题。 (在很多很多有用的功能中)它突出显示了当命名空间错误时(基于程序集的文件夹层次结构和根名称空间),并且可以为您解决它。 请注意,与Java不同的是,有时候非常有理由让类在命名空间中, 而不是由目录结构推断的类。 一个很好的例子可能是扩展方法类,它们需要在调用它们的类的范围内。 因此常见的有: /myProject /extensions /MyExtensionMethodClass.cs 有一个像myProject这样的名称空间 ...
  • 我遇到了类似的问题,原因是“默认工作区”中名为.required的变量。 也就是说,当你启动R时,它会加载Windows上的工作空间,例如,“我的文档”中的.RData文件或类似的地方。 看看ls(all=TRUE) - 列出所有变量,甚至是那些以句点开头的变量。 如果你在那里看到.required ,并且.required包含类似“XLConnect”的内容,那么你(可能偶然)告诉R每次加载这个工作区时加载XLConnect。 删除此变量 rm(.required) ..并保存工作区 q("yes") ...
  • 假设您的文件位于/home/mytetris/Tetris.java中 然后你需要在目录home中运行“java mytetris.Tetris”。 因为你指定了包mytetris,它会在mytetris目录中找到你的文件,在那里它会找到类Tetris。 Suppose you have your file in /home/mytetris/Tetris.java Then you need to run "java mytetris.Tetris" in the directory home. Beca ...
  • 这没什么好担心的。 有些Java类在过去15年中已被弃用,但它们仍然位于核心库中以实现向后兼容。 即使一大堆javax。*类被弃用,它们也不会消失。 您可能也想看看Java 9的模块化系统 。 This is nothing to worry about. There are Java classes that have been deprecated for the last 15 years but they're still in the core libraries for backwards co ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)