- Feb 3, 2005
- 213
- 0
- 0
This may be a simple one for the bigger brains of the forums, but I'm a scripting novice so it is driving me nuts.
file_a contains:
1
2
3
4
5
6
7
file_b contains:
7 hens
22 gorillas
31 kangaroos
working scriptlet:
i=$(awk /7/ file_a)
awk /$i/ file_b
output would be:
7 hens
It does not work if the first awk does not match:
i=$(awk /9/ file_a)
awk /$i/ file_b
output:
7 hens
22 gorillas
31 kangaroos
Because $i equals nothing, all lines are printed. So what I am trying to do is "if $i" equals nothing, stop running and print "no match".
This is being run on a stripped version of net BSD, so I really only have awk and sed - no grep.
Can anyone help?
Thank you in advance.
file_a contains:
1
2
3
4
5
6
7
file_b contains:
7 hens
22 gorillas
31 kangaroos
working scriptlet:
i=$(awk /7/ file_a)
awk /$i/ file_b
output would be:
7 hens
It does not work if the first awk does not match:
i=$(awk /9/ file_a)
awk /$i/ file_b
output:
7 hens
22 gorillas
31 kangaroos
Because $i equals nothing, all lines are printed. So what I am trying to do is "if $i" equals nothing, stop running and print "no match".
This is being run on a stripped version of net BSD, so I really only have awk and sed - no grep.
Can anyone help?
Thank you in advance.