Simple AWK command to check if the directory path is correctly written

awk

The POSIX portable file name character set consists of the upper case letters A to Z, the lower case letters a to z, the decimal digits 0 to 9, the full stop, the underscore, and the hyphen. I want to produce an error if the field is not so.
I already can check that the field must start with a "/" but am having difficulty reporting errors for illegal characters within the file path given.
The code I have:

{if ($6 !~ /[a-zA-Z0-9_\/.-]{0,100}$/) print NR ": ERROR The directory contains illegal characters" }

This doesn't find illegal characters and report them as it should.
Input: /Bin**/home
Output: Warning illegal characters found (Because of the "**")

Looking to fix my AWK command.

Best Answer

how about this ?

awk '$6~/[^a-zA-Z0-9_\/.-]/{print NR ":Illegal Characters"}' filename
Related Question