I am looking for an awk command that prints an error message if the username it is reading from /etc/passwd does not follow certain guidelines. The guidelines are: This field must start with a letter and may contain up to a total of 8 letters, digits, underscores, hy-phens, and dots. I have managed to make sure the username is 8 characters or fewer but I am having difficulty with a command that means it must only be letters, digits, underscores, hy-phens, and dots.
Current code:
{if (length($1) >= 9) print "Error: The username has too many characters on line " NR}
{if ($1 != [a-z]) print "Error"} //Here is where I need the command.
Do I need multiple if statements? If so can you help me find an appropriate awk statement
Thanks
$1
against that in a rule.But if this is homework that may not be the intent. – steeldriver Oct 10 '16 at 23:17/li/
part) to test against your requirement. You may find www.regular-expressions.info helpful. – steeldriver Oct 10 '16 at 23:29Or something along the lines of this
– Valentino Oct 10 '16 at 23:41^[A-Za-z]
), followed by a number of letters, digits, and selected punctuation. With some implementations of awk, you can specify a number of repetitions explicitly like{m,n}
but others may only support a zero-or-more repetition modifier*
in which case you will need to check the length separately. – steeldriver Oct 11 '16 at 01:54