Bash - Remove duplicate lines in file

gawk " !x[$0]++" inputfilename.txt > outputfilename.txt

Perl - Variables

#!/usr/local/bin/perl
 
# Example showing how to define different variables.
# ==================================================
 
my $someString="Hello World!";  # Variable holding a string.
my $someNumber=3.1415;          # Variable holding a number.
my @someArray =("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
 
# Output all the variables defined.
$someNumber = $someNumber*2;
print "$someString\n";
print "$someNumber\n";
print "@someArray\n";

Perl - Installation and setup of Perl

  1. Download Windows version of Perl at ActiveState.
  2. Install it.
  3. Save the following code in a file and name it tutorial.perl .
    #!/usr/local/bin/perl
    print 'Hello world.';		# Print a message    
     
  4. Open the Command Prompt.
  5. Execute the following command:
    perl tutorial.perl
     
  6. It should display Hello world..

Perl

DOS - Padding zeros

@ECHO OFF
 
SET i=1
FOR /L %%V IN (1,1,1003) DO (
CALL :Increment
)
 
ECHO "Done showing zero padding."
 
GOTO :EOF
 
:Increment
  REM Padding zeros
  SET filename=%i%
  if %i% lss 1000 set filename=0%i%
  if %i% lss 100 set filename=00%i%
  if %i% lss 10 set filename=000%i%
 
  ECHO %filename%.txt
 
  SET /a i+=1
  GOTO :EOF

Output will look like:
....
0889.txt
0890.txt
0891.txt
0892.txt
0893.txt
0894.txt
0895.txt
....

Varia - WinMerge useful setting

I don't know why, by default, WinMerge is set to show the difference on word level. It should be on Character level. Every time that I install it, I have to change this setting.
The setting is located at Edit->Options->Editor->Line Difference Coloring. Check Character level.

DOS - Fast way to delete a lot of files and folders

del /f/s/q foldername > nul
rmdir /s/q foldername

The first line is to delete files and output to nul to avoid the overhead of writing to screen for every singe deleted file.
The second line is to delete the remaining directory structure.

DocBook - Docbook predefined special characters

Character Named entity Description
™ Trade mark
© © Copyright
® ® Registered
± ± Plus or minus
✓ Check mark
✗ Ballot X
↑ Up arrow

DocBook - Using Entities to define a shared string

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book [
  <!ENTITY product-name "Docbook">
  <!ENTITY product-version "4.5">
]>
<book>
  <chapter>
    <title>Tutorial: Using Entities to define a shared string</title>
    <para>The latest version of <application>&product-name;</application> is &product-version;.</para>
    <para><application>&product-name;</application> is best used to write documentation.</para>
  </chapter>
</book>

Finance - Commodities

Oil

Oil price will fall if:

  • OPEC raises its production quota.
    • http://finance.yahoo.com/news/Oil-falls-below-99-ahead-of-apf-3943285001.html?x=0&sec=topStories&pos=3&asset=&ccode=

U.S. Energy Department's release Tuesday of its monthly short-term energy outlook and weekly petroleum inventories report.

Syndicate content