tell me how in ubuntu using grep to pull out only the necessary lines from the file. There are two files 1.txt (2 million lines), 2.txt (400000 lines) in 1.txt a list of lines that need to be checked for the occurrence of lines from 2.txt. if in 1.txt we find a line from 2.txt then we add to the file 3.txt whole line.
1 answer
if it is enough to 2.txt string from 2.txt into a string from 1.txt , then for example:
$ grep -F -f 2.txt 1.txt > 3.txt example:
$ cat 1 1 2 3 55 $ cat 2 3 4 5 $ grep -F -f 2 1 3 55 - file 3.txt after running grep -F -f 2.txt 1.txt> 3.txt is empty :( - bandsed
- if there are no error messages, I can assume at least three explanations: 1. there are no common lines in the files. 2. In one or two files, the lines are not separated by the character (s) that grep expects. 3. under the name grep , it’s not gnu / grep that is more or less current, but something exotic. for example, no grep at all, but some kind of stripped down substitute. - aleksandr barakin
- 1. in the file 1.txt there are exactly lines with an entry from 2.txt 2. ending of lines \ n 3. grep -V grep (GNU grep) 2.16 I have been fighting for the second day, tried to make selections using the wines of the software KeyWordKeeper but due to the fact that in 2.txt many lines (400k) KeyWordKeeper 18 hours only took into account the lines for the sample, in the end there was not enough memory. - bandsed
- in the 1.txt file there are exactly lines with an entry from 2.txt - please specify what goes where. in
1.txtthere is a line of type12345, and in2.txtthere is a line of type234? - aleksandr barakin - oneProblem solved, the whole thing was in different encodings - bandsed
|
command get exact matches of strings. but such a solution would work, in my opinion, longer than what I suggested in the answer. besides, the question is aboutgrep. By the way, what is the awk label for? - aleksandr barakin