how to read in shell

how to read 3rd entry of 6th line from the bottom in /etc/passwd file using shell script

awk -F":" ' NR == 6 { print $3 } ' /etc/passwd 

If I understand correctly and by "entry" you mean column:

awk '{x[NR]=$3}END{print x[NR-5]}' FS=":" /etc/passwd 

tail -6 /etc/passwd | head -1 | awk -F":" '{print $3}'

Or (zsh/bash/ksh93):

< <(tail -6 /etc/passwd) IFS=: read a b c d;echo "$c"
tail -6 /etc/passwd | head -1 | cut -d: -f 3

Cheers,
Ozgur

awk '{ line[NR]=$0} 
     END { 
	         for (i=NR-5; i<=NR; i++) { 
			    n=split(line,arr,":")
				print arr[3]
			 } 
		  }'  "/etc/passwd"

and this,

sed -e :a -e '$q;N;7,$D;ba' /etc/passwd | sed -n '1s/\(.*\):\(.*\):\(.*\):\(.*\):\(.*\):\(.*\):\(.*$\)/\3/p'

OP requested for 6th line from the bottom of /etc/passwd :slight_smile:

Another awk solution :

awk -F: -v From=6 '
   { uid[NR % From] = $3 }
    END { print uid[(NR+1) % From] }
' /etc/passwd

I didn't read it properly