Thursday, September 13, 2007

Some random one-liners

The following will generate 8-digit unique number

  • /usr/bin/perl -e '$range=1000000;$min=10000000;$randomN=int(rand($range))+$min;print "$randomN\n";'

Translating Milliseconds to the Localtime

  • echo "$MILLIS" | /usr/bin/perl -e 'chomp($in=);$res=localtime($in/1000);print "$res\n";'

Getting specific position: begins at 99th position and lasts for exactly 15 bytes

  • sed -e 's/^\([^,]\{98\}\)\(.*\)$/\2/g' -e 's/^\([^,]\{15\}\).*$/\1/g' -e 's/^[^0-9][^0-9]*//g' -e 's/ //g' pbt*.ach

Tar-up some dir on local system while piping through ssh to a remote system

  • (cd $base/$reports/..; tar -cf - $reports) | ssh anotherhost "(test -d $remoteDir || mkdir -p $remoteDir); cd $remoteDir; tar -xf -"

0 Comments:

Post a Comment

<< Home