tac – reverse the lines of a file

May 6th, 2009

Before you write a script like this look for someone else who has already done 99% of the work. The tac command will reverse the lines of a file and is therefore extremely useful in various situations.

The tac man page has further details.

Basically, tac will cat a file backwards. However, many operating systems do not include the tac command by default and for some operating systems tac is not yet available.

On many systems you may use tail. I believe the version of tail on Solaris may have a different flag.

cat myfiile | tail -r

By default the -r flag will cause tail to print the entire file rather than just the tail portion of the file.

Be very wary of the rev command availible on most BSD based systems. The has further details. However, this command will reverse the chracters rather than the lines of a file.

The following command sequence should actually reverse the lines on most systems :

cat -n myfile | sort -nr | cut -c 8-

However, please keep in mind that if you have a very long file then this may not work correctly. In which case using a script say in ruby or a version of tac for your system may be the best approach.

The following command sequence should actually reverse the lines on most systems :

cat -n myfile | sort -nr | cut -c -f2-

You can also use sed to reverse the file :

cat myfile | sed ‘x;1!H;$!d;x’

Probably the most memorable of these is the following Perl comamnd

cat myfile | perl -e ‘print reverse <>‘

Perl is available for many systems as is ruby. Perhaps the script in ruby to reverse the lines is not actually all that silly.

If you are running Windows and you really do not want to install perl or tac then check out this I found this article which may work?

DokuWiki Auto-detect User Interface Language

May 3rd, 2009

Until a DokuWiki plugin or configuration option is included with a base DokuWiki installation, then the following information should assist you if you wish to set the interface language of DokuWiki presented to your visitors, based upon their browsers preferred language configruation.

This great article hosted within the DokuWiki Tips name space has the basic lowdown. The code posted by Markus Birth on the 2008-07-16 at 20:05 may be copied into your (new/existing) conf/local.protected.php file and then configured so that the languages you would like to support are enabled.

Before you apply any of these features make sure that you have a full backup of your DukoWiki installation. It is far to easy to make a simple mistake, that will take you an hour to pin down and rectify. This is particularly true if you are editing multiple files. Save your self some pain and ensure that you have a complete backup of your DokuWiki before you proceed. If you are looking for an open source automated backup solution, then have a look at LBackup

After these functions from the link above are added into your conf/local.protect.php file, comment out the line that starts with “$conf['lang'] = ‘” in within your conf/local.php file. Once you save the conf/local.php file, as soon as someone visits the DokuWiki the interface will be presented based upon their browsers default language configuration.

Keep in mind that this approach will also enable features such as the the DokuWiki interface language being selected based upon your name space and other settings. I would recommend that you read the linked article carefully before applying any changes to your DokuWiki configuration. This will ensure that you fully understand what features this code will enable on your DokuWiki installation. You may decide that only a subsection of the code will do everything you currently require.

Finally, a word of warning regarding this approach. You should be aware that altering settings from within the DokuWiki admin interface may mean that changes applied to the conf/local.php file may be overwritten. As such you may need to re-comment out the line startting with “$conf[lang'] = ” in your conf/local.php file. If you make any changes with the web-based configuration system. I am guessing that this whole situation will be resolved in an upcoming release of the the fantastic DokuWiki.