Calculate the sum of digits of a given number
echo 1234 | sed 's/\(.\)/\1\+/g' | sed 's/.$//' | bc -l
perl -e 'print eval join "+", split //, 12345;'
rot13 "encryption" of a file:
tr A-Za-z N-ZA-Mn-za-m < file
-
hint on 2-dimensional arrays in Perl:
$width = @{$array[0]};
$height = @array;
zig-zag scan in Perl
-
How to list just directories:
ls -d */
ls -l | grep ^d
find . -maxdepth 1 -type d
ls -F | grep /$
ls -1 | while read line; do if [ -d "$line" ]; then echo $line; fi; done
perl -e 'opendir(DIR, "."); foreach(readdir(DIR)){print $_ ."\n" if (-d $_);}'
just kidding ;)
...
-
Remove the last character from a string/variable (bash)
echo ${var:0:${#var}-1}
echo ${var%?}
echo $var | sed 's/.$//'
You could also use chop ;)
Find all numbers from 1 to 999999, which are palindromic in base 2 and base 16