Tuesday 2 October 2012

Continuing long lines in a batch script

Unintentionally I found for myself that a batch script has a nice feature to break long lines without loosing of possibility of reading them.

Imagine, you have some weird combination of commands as below that is not put completely in one line of a screen.

some-command-with-many-arguments | another-lomg-command-with-its-own-arguments | etc | etc | etc

If the line of a code cannot be shown within one line on a screen it will be i) either turned and the rest of line will be shown below on one or more lines or ii) continued out of edges of the screen with a horizontal scrolling bar. Both of them are not convenient because we not able to observe the code entirely.

Fortunately, modern batch scripts (in XP, Vista, Win7) have blocks implemented by brace:

(
    some-command-with-many-arguments 
) | (
    another-long-command-with-its-own-arguments 
) | etc | etc | etc

I known this feature (because I used brace in the if-else and for statements) but did not realised right now.

So, this gives us good possibility to break the long line into a several lines without loosing of functionality. This is better than nothing and is better than undocumented feature using the DOS-like escaping character ^ at the very ending of the line because you have to look after that this character is in the lastest character of the line. See the same example with the esacaping character:

some-command-with-many-arguments | ^
another-long-command-with-its-own-arguments | ^
etc | etc | etc

Unix shell scripts are featured to continue long commands using by backslashes since the begining of the Unix wolrd.

some-command-with-many-arguments \
| another-long-command-with-its-own-arguments \
| etc | etc | etc

Saturday 29 September 2012

How to concatenate multiple lines in console (bash, cmd)

If for some reasons you need to have concatenated lines try one of the recipes below.

Monday 25 June 2012

Merge and sort many logfiles having multiline entries

logmerge is the small and powerful script to merge two or more log files so that multiline entries appear in the correct chronological order without breaks of entries. Optional arguments control an adding of descriptive fields at the beginning of each line in the resulting combined logfile. Reading of .gz/.bz2 files is available.

Tuesday 15 May 2012

Regular Expression Analyzer

Neat online tool. Regular expressions are described in the human-friendly style.

Regular Expression Analyzer

Sunday 25 March 2012

Universal way to identify your external IP and more

There are many such kind of resources in Internet but this is the best. It allows the numerous structured data and it has nice name. Meet http://ifconfig.me/.
Command line interface
Using curl
curl ifconfig.me
or wget
wget -qO - ifconfig.me/ip
JScript
JS
var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.open('GET', 'http://ifconfig.me/ip', false);
xmlhttp.send();
 
var ip = xmlhttp.responseText;
JS+XML
var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.open('GET', 'http://ifconfig.me/all.xml', false);
xmlhttp.send();
 
var ip = xmlhttp.responseXml.getElementsByTagName('ip_addr')[0].text;
Having JSON library you can read and parse JSON data:
var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.open('GET', 'http://ifconfig.me/all.json', false);
xmlhttp.send();
 
var data = JSON.parse(xmlhttp.responseText);
var ip = data.ip_addr;
VBScript
Dim xmlhttp, ip
 
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "GET", "http://ifconfig.me/ip", False
xmlhttp.send
 
ip = xmlhttp.responseText

Thursday 5 January 2012

Artist/Album Info in Foobar2000

foobar2000 is perfect mediaplayer for Windows platforms. It is kind of those applications whose functionality is extendable simply adding plugins. One of these finest plugins is Run services that allows to run external applications and scrpts from within foobar2000.

I use Run services to view/edit information about albums or artists stored in plain text files. Let's consider how it is possible.