Hi, verse123. Here's how I read your program specification.
Quote:
Originally Posted by verse123
. . . print out lines that match . . . The matched words are also in the same column . . . the order of the output does not matter . . . "DOG1" should appear in the output file 4 times . . . "DOG3" should appear twice in the output
|
Hope I understand you. Here's the input file I copied from your post.
Code:
$ cat dogs.txt
DOG1 233 1
DOG1 231 1
DOG4 230 5
DOG1 0.5 3
DOG3 0.04 2
DOG0 4 23
DOG1 5 0.1
DOG3 63 5
Here's the program I use to parse the file.
Code:
$ cat dog-finder.awk
#! /usr/bin/awk -f
BEGIN {
# FS=" "
# OFS=" "
}
{
i=$1
if (i in array) {
print array[i]
delete array[i]
print $0
} else {
array[i]=$0
}
}
Here's the output my program produced when I fed it the input file. I believe this program meets your specifications as I understood them.
Code:
$ ./dog-finder.awk dogs.txt
DOG1 233 1
DOG1 231 1
DOG1 0.5 3
DOG1 5 0.1
DOG3 0.04 2
DOG3 63 5
HTH