I've come across some weird problem that I can't solve by myself. I've got two files, content as follows:
File1.txt
Butterscotch;lkt+4S7Yhzf/g
Sox;WrWMzN6HD
Table;K4yPIK+SFfTFs
tram;YaY3opP9ie
number;e/WwiF5aihUY
Buttler;Nsadlkt+4S7Yhz
wzahwahwah;PYaY3opP9ieH
File2.txt
Butterscotch;lkt+4S7Yhzf/g
Sox;WrWMzN6HD
Table;K4yPIK+SFfTFs
tram;YaY3opP9ie
number;e/WwiF5aihUY
I need to find differences between those two files but only for entries that are before semicolon, so I first use awk to get those entries:
awk 'BEGIN {FS=";"}; {print $1}' File1.txt > Output1.txt
awk 'BEGIN {FS=";"}; {print $1}' File2.txt > Output2.txt
New files contain entries as follows:
Output1.txt
Butterscotch
Sox
Table
tram
number
Buttler
wzahwahwah
Output2.txt
Butterscotch
Sox
Table
tram
number
Then I use grep -Fxvf Output2.txt Output1.txt > Diff.txt to print out the differences between Output2.txt and Output1.txt so my file looks like this:
Diff.txt
Buttler
wzahwahwah
Now the tricky part. I need to find and print out to another file whole lines from File1.txt that start with entries from Diff.txt. I'm declaring a variable and do something like this:
variable=$(cat Diff.txt)
grep $variable Output1.txt > Delete.txt
So for this example I should get something like this:
Delete.txt
Buttler;Nsadlkt+4S7Yhz
wzahwahwah;PYaY3opP9ieH
But unfortunately I get an error:
grep: wzahwahwah: No such file or directory
File Delete.txt instead of desired data contains:
/home/working/File1.txt:Buttler;Nsadlkt+4S7Yhz
So it's far from what I need to get. What I've noticed is that when I remove from File1.txt
wzahwahwah;PYaY3opP9ieH
I get no errors and my desired file looks like:
Buttler;Nsadlkt+4S7Yhz
Any ideas why this isn't working?