Using Bash Script to Find Line Number of String in File

Given that your example only prints the line number of the first occurrence of the string, perhaps you are looking for:

awk '/line/{ print NR; exit }' input-file

If you actually want all occurrences (eg, if the desired output of your example is actually “2\n3\n”), omit the exit.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)