Awk (or Sed) to show current field number from the Field Seperator

How can I awk (or sed) something to do a search and print out the Field NUMBER (position in the line) when it finds a match?

Example File has 3 lines:

This is - a test file.
This is a - test file.
This is a test - file.

Objective:
Find the positions of the "-"

Desired Outcome:
3
4
5

I can grep, awk -F-, and sed to find them (and / or do other things), but thought awk would have had a variable like FS or something that might help out.

Thoughts?
Thank you,
Gene
genehackmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rockiroadsCommented:
try grep -n

-n prints line number in file
0
rockiroadsCommented:
sorry my mistake, just reread your example, ignore what I wrote
0
rockiroadsCommented:
have a look at using index in AWK, I think that might be it
hopefully some other expert can help ya cos Im now off home
have a good evening, sorry about my cockup
0
ahoffmannCommented:
awk '{for(n=1;n<=NF;n++){if($n=="-")print n}}' file
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
genehackmanAuthor Commented:
That worked perfectly !
Thank you,
Gene
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.