I want to compare line by line, but only in the 2nd column from a file using bash
What I'm trying to do is read in a file, then compare the elements.
Say I have this file:
JOHN SMITH
JOHN SMITH
JIM JOHNSON
I want to be able to see if SMITH equals SMITH, if it does, I want to change the name of the second one, then store them both. Then I'll take the second SMITH and compare it to JOHNSON, if they don't equal, that's fine, store the names somewhere and move on.
I have this, but I kind of wanted to use awk, I just can't figure it out:
while read -a line
do
if [ ${line[1]} == ${line[1]} ]
then
echo -e "${line[1]}" >> names5.txt
else
echo "Not equal."
fi
done < names4.txt
Last edited by gappel23; 03-27-2018 at 06:19 PM.
|