0

I wanted to use comm to compare 2 lists: one consists of randomly generated words:

cat /dev/urandom | head -n 10000 | strings | tr 'A-Z' 'a-z' | sort

the other one is an english dictionary:

wget -q0- <URL> | sort

(I can't really give away the URL) I tried saving both lists to temporary files and then used comm -12 file1 file2 and it worked, but now i want to do it without creating those temporary files. Is there a way?

2 Answers2

1

Your code (with the useless use of cat refactored) can be trivially rewritten to use a Bash process substitution:

comm <(head -n 10000 </dev/urandom |
        strings | tr 'A-Z' 'a-z' | sort) <(wget -q0- <URL> | sort)

However, unless your goal is to expedite the heat death of the universe, your code looks massively inefficient. Perhaps you should explain what you are trying to accomplish? (Plus if you want to find the frequency of dictionary words in /dev/urandom output, I believe strings will be filtering out any really short words.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • I was revising for an exam and this was one of the exercices, it specifically mentioned using strings and the task mentioned that efficiency isn't really a problem. Anyways your solution worked ! thanks ! –  Jan 07 '14 at 10:37
0

Btw i found another solution, not using comm.

((head -n 10000 </dev/urandom | strings | tr 'A-Z' 'a-z' | sort | uniq) ; (wget -q0- <URL> | sort)) | sort | uniq -d

It's not very efficient, but it works (uniq -d only prints duplicated lines = lines in both files).