I found out that (grep mn "word" fileName) gives me only the nth occurrence of the word which is exactly what I need. The problem is that the original code I'm working with have "grep -E "word" fileName" in it and I need to make an update so it only considered the nth occurrence only. So my question is what is the right syntax to achieve that, is it (grep -E m4 "word" fileName) or (grep -Em4 "word" fileName) and thx in advance.