awk - Shell Script - can't find string in file using grep -
awk - Shell Script - can't find string in file using grep -
i've come across weird problem can't solve myself. i've got 2 files, content 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 find differences between 2 files entries before semicolon, first utilize awk entries:
awk 'begin {fs=";"}; {print $1}' file1.txt > output1.txt awk 'begin {fs=";"}; {print $1}' file2.txt > output2.txt new files contain entries follows:
output1.txt
butterscotch sox table tram number buttler wzahwahwah output2.txt
butterscotch sox table tram number then utilize grep -fxvf output2.txt output1.txt > diff.txt print out differences between output2.txt , output1.txt file looks this:
diff.txt
buttler wzahwahwah now tricky part. need find , print out file whole lines file1.txt start entries diff.txt. i'm declaring variable , this:
variable=$(cat diff.txt) grep $variable output1.txt > delete.txt so illustration should this:
delete.txt
buttler;nsadlkt+4s7yhz wzahwahwah;pyay3opp9ieh but unfortunately error:
grep: wzahwahwah: no such file or directory file delete.txt instead of desired info contains:
/home/working/file1.txt:buttler;nsadlkt+4s7yhz so it's far need get. i've noticed when remove file1.txt
wzahwahwah;pyay3opp9ieh i no errors , desired file looks like:
buttler;nsadlkt+4s7yhz any ideas why isn't working?
instead of cat , subsequent grep utilize grep:
grep -ff diff.txt file1.txt buttler;nsadlkt+4s7yhz wzahwahwah;pyay3opp9ieh shell awk grep
Comments
Post a Comment