What's the software you're using? To get the output I think you want you don't need a regular expression in awk, since the number of fields is four when there's a letter and three when it's missing. awk '{if (NF!=4) print "= N"; else print "= " $3}' < /tmp/data | nl | sed 's! *!line !' -- Ed Cashin <ecashin at noserose.net>