Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I just started to learn awk/sed/grep and we need to write a shell script which will randomly choose 2 numbers and from those numbers pick words out of a dictionary file. There is more but thats where i am having problems so far.
This is what i have got for it:
#!/bin/bash
#Created by me
#November 17, 2003numb_ppl=$(grep -c '.*' /usr/share/dict/words) #finds number of ppl in file
num1=$(perl randm.pl.txt $numb_ppl) #uses perl random script to choose
number between 1 and numb_ppl
num2=$(perl randm.pl.txt $numb_ppl)grep -n '.*' /usr/share/dict/words > holdgrep #redirects output to a new file
#i have checked here and everything works fine
awk -F: '/$num1/{print $2}' holdgrep
--------END OF S-----------I never get an output for field2 in the holdgrep file. I am assuming my syntax for a variable in an awk statement is off somehow but i am not sure. Does anyone have any ideas?

Is your instructor ok with you posting homework questions?
Anyway, you're on the right track so I'll give you a hint; look in awk (or in my case, gawk) man pages for the -v or --assign option.
Good luck.

Hmm, well the -v that i read didnt make sense till someone on another board explained it to me (odd, you both thought the same thing), but i figured out the problem in my code. I needed to add single quotes around $num1
But my teacher didnt like the way i was coding. Too complicated, sheesh. So he showed me how he wanted it. Same result, different code.
How's that for teaching creative coding :S
Thanks though, i did learn some about -v option

![]() |
How Get Mac Address
|
emu10k1/AC97 optimal mixe...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |