Tuesday, January 16, 2007

FIRST occurence of a pattern - BASH beginner


In order to find the line number of first occurrence of the word "bash" in the following file

$ cat shells
korn is excellent
c is superb
bash is best
bash is handy
all are best

$ grep -n "bash" shells | sed '1!d' | awk -F : '{print $1}'
3

$ awk -F : '/bash/ {print NR}' shells | sed '1 !d'
3

No comments:

© Jadu Saikia www.UNIXCL.com