Christian Mayne

Christian Mayne

Spliting strings with awk / nawk

I mainly use nawk to extract elements from a string where I know the position (eg to get just the filenames when running a grep and I'm just too lazy to remember the correct grep syntax). so, to extract field number x from strings in where the field separator (FS) is y: $ nawk '{ FS="y"; print $x }'

Checking for a valid domainname

Very quick function to test a domain name is valid:     function validDomain($domain)     {         // Test domain is actually valid         if (preg_match('/^[a-z]+([a-z0-9-]*[a-z0-9]+)?(.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/i', $domain))         {             return TRUE;         }         return FALSE;     } The key here is the regular expression (delimited by the forward slashes at each end): /^[a-z]+([a-z0-9-]*[a-z0-9]+)?(.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/ This basically translates ...
No results found.