Need some help with grep

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

Hello all, I'm relatively new to Linux/Unix. Took an introductory course to get myself exposed to all the different commands so I'd be ready for my scripting class. I do know a lot of the commands and their purpose but unfortunately I'm having some problems with syntax and such. All is explained below.
:wall:

  1. The problem statement, all variables and given/known data:
    The script I'm writing must contain the following:
    Write a command syntax for showing:
    search for line starting with letter Q
    search for line ending with string "ab"
    search for BOB, Bob, BOb or BoB
    search for any phone numbers in the format "999-99999"
    search for three letter word starting with "b" and ending with "t" like bit & but

  2. Relevant commands, code, scripts, algorithms:
    grep and some sub-commands

  3. The attempts at a solution (include all code and scripts):
    What I've written thus far:
    # Searching for lines starting with Q
    `grep -i '^Q' *`

# Searching for lines ending with the string ab
`grep '$ab' /etc`

# Searching for BOB Bob BOb or BoB
`grep '[BOB][Bob][BOb][BoB]' *`

# Searching for phone numbers in 999-99999 format
`grep '[0-999][0-99999]' *`

# Searching for words beginning with b and ending with t
grep (incomplete)

I've made several attempts just to make the first three commands work. Had a lot of command not found errors and the like. I'm stumped here. Even when the script runs nothing appears so I'm assuming that nothing matches but I'm almost certain here that I'm wrong. I've used grep with success before but it seems that using it in script is a whole different animal.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Baker College of Jackson, Jackson MI, United States, Instructor Sohail Sadiq, LUX 211 Shell Scripting (Unable to post a link)

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Why's it in backticks? What filename is * supposed to be? Why the -i? Otherwise it looks ok.

$ means 'end of string', so you've got it on the wrong side of ab. Also, why do you have it in backticks? And what filename is /etc supposed to be? Needs to be a file, not a dir. Otherwise, looks OK.

Doesn't work that way. [BOB] looks for the letter B, or the letter O, or the letter B.

Since the first letter's always the same, you could have grep 'B[secondletters][thirdletters]' where secondletters and thirdletters are the allowable letters for those spots.

Also, you've got it in backticks again.

doesn't work like that.

grep '[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]'

Also, what filename is * supposed to be?

Are you allowed to use egrep?

that's because you keep putting them in backticks. So it runs the grep, then tries to run its output as a command.

Thanks for the input. I'll work on correcting this and get back to you.

*Edit* I fail at quoting I guess . . .

Nope. It goes "grep pattern filename". See man grep.

Without knowing what you typed, and what the contents of the files were, it's impossible to say why. But grep expects filenames.

/home/useraccount is a directory, presumably, not a filename, so won't work.

  • means 'everything in the current directory', which may not make sense either depending on what the current directory is and what's in it.

Why not just give it an actual, real, filename?