I am trying to compare these 2 files and only print out what I need as the desire output.
File1:
012345:x:9012345:9012345:John Smith:/home/bin/bash
543210:x:9876543:9876543:Troy Denver:/home/bin/bash
111111:x:9898989:9898989:Mathew Moore:/home/bin/bash
222222:x:0101010:0101010:Chuck Maxwell:/homebin/bash
333333:x:1212121:1212121:Bob Evans:/home/bin/bash
File2:
333333 ALL=(ALL) NOPASSWD: ALL
543210 ALL=(ALL) NOPASSWD: ALL
222222 ALL=(ALL) NOPASSWD: ALL
Desired Output:
333333 Bob Evans
543210 Troy Denver
222222 Chuck Maxwell
this is what I've done
readarray num1 < file1 | awk -F'[ ]' '{print $1}'
while read -r $num1;
do grep "$num1" file2
echo "$num1" | awk -F':' '{print $1,$5}'
done < file3.txt
With GNU join, sort, sed and bash:
join -j 1 -t : <(sort File1) <(sed 's/ /:/' File2 | sort) -o 1.1,1.5 | sed 's/:/ /'
Output:
222222 Chuck Maxwell 333333 Bob Evans 543210 Troy Denver
See: man join