How to return the line number of the first occurrence of a text in a file in linux? For instance, a file as follows.
12:04:56 xxxx
12:06:23 xxxx
12:09:11 xxxx
12:09:13 xxxx
12:10:12 xxxx
Can anyone provide a line command which returns 3 if the desire text is "12:09:"?
Try this :
awk '/12:06:23/{print NR;exit}' file
and with grep and cut :
grep -n -m1 "12:06:23" file | cut -d':' -f1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With