ghostdog74, actually your explanations are very nice and incredibly helpful. thanks very much. the links to awk sites are also great- thanks!
here's what i came up with:
Code:
#!/bin/bash
awk '{
if (($2" "$1) in animals)
{print $2,$1> "animaltemp"}
else {animals [$1" "$2]=""}}
END {
for(i in animals) {print i>"animaltemp2"}
}' animals
This gives me
Code:
> more animaltemp
dog cat
hamster dog
and
Code:
> more animaltemp2
pig hamster
dog cat
wolf pig
hamster dog
columnA columnB
My final wish is to be able to create a file like animaltemp2 but with markings at dog cat and hamster dog so that I know that I removed reciprocals for them.
I tried to adapt an earlier script from coulcix with a grep and a while statement, but it didn't work. Could anyone tell me why and how to accomplish this last task? Here's what I tried:
Code:
#!/bin/bash
while read line
do
if grep -qf animaltemp animaltemp2
then
echo $line recip deleted >> "animaltemp3"
else
echo $line >>"animaltemp3"
fi
done < animaltemp2
the result is:
Code:
>more animaltemp3
pig hamster recip deleted
dog cat recip deleted
wolf pig recip deleted
hamster dog recip deleted
columnA columnB recip deleted
Much thanks again!