Results 1 to 4 of 4
I have a small script that loops through a list of words in one file and compares them to a second list of words. If the words in list1 also ...
- 08-21-2009 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 2
compare two lists without grep?
I have a small script that loops through a list of words in one file and compares them to a second list of words. If the words in list1 also exist in list2 output those words to list3.
for i in `cat ./list1` ; do
if grep -wq "$i" ./list2 ; then
echo "$i" >> ./list3
fi
done
The problem is I am stuck with busybox and this grep doesn't have -w so it does a partial match. I need some way to compare whole words only.
- 08-21-2009 #2
This is actually a line by line compare, so not exactly what you are asking.
But if your busybox is compiled with comm,
you might try this:
BusyBox - The Swiss Army Knife of Embedded LinuxCode:comm -1 -2 file1 file2 > file3
- 08-21-2009 #3
sry, comm needs sorted lists.
So, busybox would have to include: sort, uniq, comm
Code:sort file1 | uniq > tmp_file1 sort file2 | uniq > tmp_file2 comm -1 -2 tmp_file1 tmp_file2 > file3 rm tmp_file1 tmp_file2
- 08-21-2009 #4Just Joined!
- Join Date
- Aug 2009
- Posts
- 2
Don't have those either. I came up with this and it seems to work. I haven't tested every combination but . . .
Thanks
for i in `cat ./list1` ;do
awk -v var=$i -F, '$1==var' ./list2 >> ./list3
done


Reply With Quote