我有两个文本文件,一个包含关键字和短语(file1.txt),另一个基于段落的文本文件(file2.txt)。我正在尝试查找file1.txt中出现在file2.txt上的关键字/短语
下面是一个示例数据:
文件1 (file1.txt):
123 111 1111
ABC 000
A 999
B 000
C 111
Thank you
文件2 (file2.txt)
Hello!
The following order was completed: ABC 000
Item 1 (A 999)
Item 2 (X 412)
Item 3 (8 357)
We will call: 123
我正在编写一个Bash脚本,其中我需要查看命令的输出,并根据该输出执行某些操作。为了清楚起见,此命令将输出几百万行文本,可能需要大约一个小时。
目前,我正在执行该命令,并将其传递到一个while循环中,该循环一次读取一行,然后查找特定的条件。如果存在该条件,则更新.dat文件并重新打印屏幕。下面是脚本的一个片段。
eval "$command"| while read line ; do
if grep -Fq "Specific :: Criterion"; then
#pull the sixth word from the line
我有一个文本文件,其中包含引号、逗号和空格。
"'x','a b c'"
"'x','a b c','1','2 3'"
"'x','a b c','22'"
"'x','a b z'"
"'x','s d 2'"
但是,当我尝试使用grep进行精确匹配时,它不会显示结果。下面是我试图使用的命令。
grep -
我有一个名为test01的文件,它当前包含:
1 Line one.$
2 This is the second line. $
3 The third $
4 $
5 This is really line 4, with one blank line before. $
6 $
7 $
8 $
9 Five$
10 $
11 Line 6 is this.
12 Seven $
13 $
14 Eighth real line. $
15 $
16 $
17 Line 9 $
18 Line 1
我有一个包含多行文本的txt文件,例如:
This is a
file containing several
lines of text.
现在我有了另一个只包含单词的文件,如下所示:
this
contains
containing
text
现在我想输出文件1中的单词,但不是文件2中的单词。我尝试了以下方法:
cat file_1.txt | xargs -n1 | tr -d '[:punct:]' | sort | uniq | comm -i23 - file_2.txt
xargs -n1将每个空格分隔的子字符串放在换行符上。
用于删除标点符号的tr -d '
我需要输出所有出现在A和Z之间的文本,但只有那些在{和}中进一步找到A和Z的文本。
下面是一个示例文件:
Once upon a AtimeZ, a mouse climbed up a tree.
Once at {the }top of AaZ {treeA, Zhe AfoundZ an apple.}
"Oh, this {is a Anice Zapple,"A saidZ the} AmouseZ.
The mouse ate {the AappleZ} happily.
输出将如下所示:
,
found
nice
said
apple
该文件不包含嵌套的
在Linux内核源代码config/*中有很多文件,我想找到一个类似于我的板的文件。
所以我试着:
egrep -l -e key1 -e key2 config/*
Sample config/file1:
This is key1
This is key2
Sample config/file2:
This is key1
Sample config/file3:
This is key2
但是结果要么是key1,要么是key2文件列表。我想要包含key1、和 key2的结果,还是有其他简单的unix可以生成结果?
在虚构的示例中,我只想列出‘file1
我运行了代码,给出了以下示例数据
md5deep find * | awk '{ print $1 }'
输出的示例
/Users/math/Documents/Articles/Number theory: Is a directory
258fe6853b1bfb2d07f512ff6bec52b1
/Users/math/Documents/Articles/Probability and statistics: Is a directory
4811bfb2ad04b9f4318049c01ebb52ef
8aae4ac36946
我想知道如何从这个字符串中获取标识符、number1和number2。
NAME IDENTIFIER-NUMBER1-NUMBER2
示例:
John Doe ABC-3901-11801
我想将标识符NUMBER1和NUMBER2分别放入不同的变量中。
但问题是,我并不总是知道它在什么位置,或者它后面是否有额外的文本,比如:
Blablabla ABC-3901-11801 John Doe Blablabla
ofc也可以有不同的数字和字母:
XYZ-46781-28102
谁能解释一下如何在php中找到这些变量。
提前感谢
假设我有一个类似这样的文本文件:
1. https://www.google.ca/
2. https://www.bob.ca/
3. https://www.cat.ca/
如果给出参考编号,我将如何将链接grep?
$ grep hello '1.' # (what should be here to just get the link?)
例如,我希望这个输出:仅https://www.google.ca/
我有一个包含一些悬空提交的存储库:
o (master) commit 3
o commit 2
o
| o (tag: danglings) dangling commit 2
| o dangling commit 1
|/
o commit 1
o initial commit
我用标签标记了最近一次的承诺,以确保它不会丢失,以防我在将来的某个时候需要它。
但是,当在egits历史中查看该存储库时,我不会得到悬空提交。它们根本没有显示出来。当我创建一个指向dangling commit 2的分支时,将显示两个提交(包括标记)。
如何防止这种情况发生?我希望看到everything,而不仅
我有以下类型的文本文件,
a b c d
-- -- -- --
1 ok device issue Some Action which
has to be taken which
is split into many lines
under d.
我尝试使用grep作为“问题”,但是只有第一行'd‘被打印出来。我得到的输出是:
1 ok device issue Some Action
我有一些VBA宏,我需要翻译所有的输出消息,但是这些消息包含在双引号之间,如下所示:
If Not IsNumeric(Sheet28.Range("I9")) Then
Call MsgBox("Error! Voucher expiry years must be a number", vbDefaultButton1 Or vbExclamation, "Error!")
Application.Undo
End If
我想要这个:
"I9"
"Error! Voucher expiry years mu
我有一个文件example.txt,它包含以下文本:
[one]: bla bla bla onebla twobla
[two]: hey heya noheya
[onemore]: i got mad and etc
我需要grep并且只显示在[myword]之后的文本:尝试以这样的方式测试它:
grep [myword] /tmp/example.txt | cut -d ':' -f 2
在每个[myword]上,它都会打印括号后面的所有内容,但是如何才能只得到我所需要的,而不是全部呢?
我只需要打印某些括号后的测试。例如,我希望只打印[one]:行中的文本,而不是[
我有一个字符串,类似:"thisissometext"。我希望在给定目录(递归)中找到所有与此字符串相对应的文本文件,或在其中使用空格和/或换行符的任何变体。例如,包含"this is sometext"或"this\n issometext"、"this\n isso metext"的文本文件应该显示在搜索中。我该怎么做?
目录中的.cpp文件包含以下文本:
/**
* Performs the standard binary search using two comparisons per level.
* Returns index where item is found or or the index where it chould
* be inserted if not found
*/
template <typename Comparable>
int binarySearch( const Comparable* a, int size, const Comparable &