CFEngine: canonify your own strings
  2014-01-30

Want to quickly canonify a string for testing ? A shell one-liner has been given by the CFEngine folks :

Example with the mac address 00:1a:d1:48:ff:d0

$ echo -n "00:1a:d1:48:ff:d0"| perl -p -e 's/\W/_/g'
00_1a_d1_48_ff_d0loic@iron[0]: ~

The mac address is correctly canonified to 00_1a_d1_48_ff_d0, but my shell prompt is appended. For extra clarity a newline can be added with the -l flag:

$ echo -n "00:1a:d1:48:ff:d0"| perl -ple 's/\W/_/g'
00_1a_d1_48_ff_d0

Neil H. Watson has also transformed this one-liner to an independent script