How do I number my for loop outputs with this method?

Currently I am outputting users and I want to number them starting with 1...

grep name list.txt | awk -F"=" '{ print $2 }' | while read user; do
        echo -e "1\t|$user"

Currently I have:

1   |  john
1   |  amy
1   |  max

I want it to look like

1   |  john
2   |  amy
3   |  max

Try:

awk '/name/ {
  printf "%s\t|\t%s\n", ++c, $0
  }' infile
awk -F"=" '/name/{ print ++cnt, $2 }' OFS='|' list.txt
1 Like