Hello,
I'm doing a script and wanted to look inside a word file and return me the first line number where you will find that word.
Thank you very much
Example( serach name) :
hello
my
name ---> Line 3
is charles
and
name is --> this NO!!! only 3
beautiful
clx
2
Try:
awk '/name/ {print NR}' file | head -1
also,
awk '/name/ {print NR;exit}' file
1 Like
this would be more succinct.
awk '/name/ {print NR; exit}' file
1 Like
clx
4
two minds worked simultaneously. I just edited the post
thank both for your time!
oh, in case you may not want to match words that contain "name", like surname, nickname, etc. you will need word boundaries to restrict that.
then use this:
awk '/\<name\>/ {print NR; exit}' file