Category

scripts

  • 10.Feb.09
    Some xargs scripts, shell | pfortuny | (1)
    Rafacas has already mentioned it, but xargs is sometimes much more useful than what it looks like. Two examples come to mind: Way too many files for rm or ls. It may well happen that a script has generated more than 10000 files in the same directory (it was your friend, not you, I know). If you try and rm * in there, you will be in trouble. Ditto if you simply want to count them with ls | wc -l. However, the following works: $ find . -type f -print0 | xargs -0 ls | wc -l (or rm instead of ...
  • 04.Feb.09
    Batch convert RTF to PDF automated, scripts, shell | pfortuny | (0)
    You've got the full details here (the OpenOffice Forum site). After following the instructions there, I was able to convert a bunch of some 500 rtf files into pdf's with the following single 'line of code' (although there must be a newline after the first quote ') $ find /Users/pedrofortunyayuso/Desktop/fichitas -name "*rtf" | while read -r i ; do /Applications/NeoOffice.app/Contents/MacOS/soffice -invisible "macro:///Standard.MyConversions.SaveASPDF($i)" ; done All the above shows my computer as an evident OS X, but this works on Windows (the referred site does the job on Windows, using, obviously a different shell construct) and, as far as I know, on ...
  • 02.Feb.09
    Currency conversion script scripts | rafacas | (1)
    In this time of crisis perhaps we need to pay more attention to financial issues. I am interested in converting some currencies so I have written a script that given two currencies, converts on to the other. The script searches the info on Google Finance's page. An example of its usage is: $ ./currencies.sh EUR USD 1 EUR = 1.316 USD The available currencies are: EUR - Euros USD - United State Dollar GBP - British Pound JPY - Japanese Yen CHF - Swiss Franc CAD - Canadian Dollar AUD - Australian Dollar INR - Indian ...
  • 17.Jan.09
    Less can do more… scripts, shell | fernape | (0)
    ... more than you think ;) less is a command that allows you to view and move forward and backwards in a file among other things. But the interesting thing is that less allows you to define a preprocessor. You can set it as the form of a shell script specified in the LESSOPEN environment variable. $ echo $LESSOPEN lessopen.sh %s This is the script that will be invoked before the actual less command (located in /usr/bin/less) is executed. The result of the script must be something readable. If you take a look at the script you will find what kind of files can ...
  • 16.Dec.08
    TTYtter: twitter client for real commandliners scripts, shell | rafacas | (2)
    If you are a twitter adict (I know you are already a commandliner ;) TTYtter is your client. TTYtter requires only Perl 5.005 or better, and either cURL or Lynx. It supports encryption as long as your Lynx or cURL does. If your client supports it you can configure TTYtter to use SSL changing the relevant URLs. These can be changed using TTYter options (-url, -rurl, -uurl, -wurl, -update, -dmurl and -frurl) or you can cut and paste the following code into your .ttytterrc file in your $HOME directory: url=https://twitter.com/statuses/friends_timeline.json rurl=https://twitter.com/statuses/replies.json uurl=https://twitter.com/statuses/user_timeline wurl=https://twitter.com/users/show update=https://twitter.com/statuses/update.json dmurl=https://twitter.com/direct_messages.json frurl=https://twitter.com/friendships/exists.json The default cURL's certificate bundle is old and may not support Twitter's current ...
  • 12.Dec.08
    awk specifying the field separator cmd, scripts | pfortuny | (1)
    $ awk -F'=| ' '{print $3}' < code.pl Prints the third field in each line of regr_FF, using the regexp '=| ' as the field separator (FS). The example regexp means "either an equal sign or a space'.
  • 17.Jul.08
    Roll the dice scripts | fernape | (5)
    Not a command, but a fun thing anyway. What if you need a dice (as I needed the other day while trying to play a game with my friends) and you don't have one? Bash can do it: $ while true;do let dice="$RANDOM % 6"; let dice=$dice+1;echo $dice;read;clear;done Though it's a long line, this is just an infinite loop in which we use the $RANDOM bash variable which generates a random number between 0 and 32767. After that, we divide it by 6 and take the remainder (so we have a number between 0 and 5) and add 1 to shift the interval ...