Home > Enterprise >  Display all line numbers for user names starting with "admin" from passwd file
Display all line numbers for user names starting with "admin" from passwd file

Time:02-09

How do I find all the occurance of a particular text in a file with a shell script. (Not using grep command)

CodePudding user response:

awk '/^admin/ {print NR;}' /etc/passwd

CodePudding user response:

A POSIX shell-only solution could be

n=0
while n=$((n 1)); IFS=':' read -r u _
do
  case "$u" in
    admin*) echo $n;;
  esac
done < /etc/passwd
  •  Tags:  
  • Related