Grep question
I have 2 files, contains only rows. I would like to remove files from left.txt beginning lines from found.txt (separator:)
My command was: cut -d: -f1 found.txt | grep -vf- left.txt > remain.txt But it doesn't work (remain.txt is an empty file). Is it a syntax error? I could not find the solution.:( Could you help me, please? found.txt contains: 00305aa421cda76cc07228111a5650a8:test1 011bbcf1eb8f65e326ebdc4f9e349c94:test2 0127f1eeffb32ed2d6001c0a3ce365f1:test3 left.txt: 4a37a393387cfef1dc8d8ee82c763003 8f55b05e6f40e6f2fb38f1a76308df64 6a8eba4925beeaf2ffa5e498f0f22c35 ae067c5c1b846ff420d94462421197c5 8d03eb07d810d9f486ca82ce2b2df106 00305aa421cda76cc07228111a5650a8 011bbcf1eb8f65e326ebdc4f9e349c94 0127f1eeffb32ed2d6001c0a3ce365f1 |
It works here...
Check output from ' cut -d: -f1 found.txt ' |
This command working:
cut -d: -f1 found.txt | less 00305aa421cda76cc07228111a5650a8 011bbcf1eb8f65e326ebdc4f9e349c94 0127f1eeffb32ed2d6001c0a3ce365f1 and this command not: cut -d: -f1 found.txt | grep -vf- left.txt | less So I don't understand what the problem.... Maybe very simple thing... |
Is there a reason for the '-' after the 'f' in the grep?
|
Quote:
Maybe grep doesn't find exact match for all the text coming from ' cut -d: -f1 found.txt ' With the lines you gave as example, that works |
Quote:
|
OP you need to think about the order in which you are doing things.
Starting with: Code:
00305aa421cda76cc07228111a5650a8:test1 Code:
00305aa421cda76cc07228111a5650a8 What you actually want is to store the data from fist file and output lines in second file that are not mentioned ... something like: Code:
awk -F: 'NR==FNR{_[$1];next}!($1 in a)' found.txt left.txt |
comm -12 left.txt found.txt
|
Quote:
Code:
$ comm -12 left.txt found.txt |
I solved. Still I don't know what was the problem.
I opened and saved all the 2 files with nano. Voalaaaa everything works with the original command. Still not understand what was the problem. The original left.txt and found.txt not my files (contains more than 10k lines). I guess maybe made by windows notepad, workpad.... I will try "comm" "awk" command too. Thank you very much for your advices. |
ahhh ... I took of the dash thinking it was an error. It does indeed work :)
You are correct that if the files were created in Windows it would mess with your results. |
All times are GMT -5. The time now is 02:31 PM. |