Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

January 3, 2016

chequePrint : Linux utility to print into cheques

The problem : As I do not write much on paper these days, writing cheques will cause some cheque leaves go waste. Earlier I had created a template in LibreOffice to solve the problem. However, I could not use that template as it was for a different bank. It was too difficult to get the alignment correct as there were boxes for days, month & year.

Solution : Write a script! Initially considered generating TeX files but zeroed in on PostScript as it would be easy to do the layout.
The script is available in the chequePrint GitHub repo.

December 3, 2014

ഷെൽ ബ്രേസ് എക്സ്പാൻഷൻ

ഒന്നിലധികം അക്ഷരങ്ങളോ വാക്കുകളോ കൂട്ടിച്ചേർത്ത് പുതിയ സ്റ്റ്രിങ്ങുകൾ നി‌‌ർമ്മിക്കാൻ പറ്റിയ ഒരു ഉപാധിയാണ് ഷെല്ലിലെ ബ്രേസ് എക്സ്പാൻഷൻ. ഉദാഹരണത്തിന് a,b എന്നീ അക്ഷരങ്ങൾ ആദ്യവും c, d എന്നീ അക്ഷരങ്ങൾ രണ്ടാമതും വരുന്ന 2 അക്ഷരങ്ങളുള്ള വാക്കുകൾ ഉണ്ടാക്കാൻ {a,b}{c,d} എന്ന എക്സ്പ്രഷൻ ഉപയോഗിക്കാം.
echo {a,b}{c,d}
ac ad bc bd
ഇംഗ്ലീഷ് അക്ഷരമാല മുഴുവൻ പ്രിന്റ് ചെയ്യണമെങ്കിൽ ഇരുപത്താറക്ഷരങ്ങളും ടൈപ്പ് ചെയ്യുന്നതിനുപകരം {a..z} എന്നു കൊടുത്താൽ മതി.
echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
echo {a..z}{a..z} എന്നു കൊടുത്താൽ aa മുതൽ zz വരെ പ്രിന്റ് ചെയ്യും
echo {1,2}{a..z}{a..z} എന്നത് 1aa..1zz,2aa...2zz എന്നും പ്രിന്റ് ചെയ്യപ്പെടും.
ബ്രേസ് എക്സ്പാൻഷൻ കാര്യങ്ങൾ എങ്ങനെ എളുപ്പമാക്കുന്നെന്നു കാണാൻ മറ്റൊരുദാഹരണം പറയാം. 2000 മുതൽ 2014 വരെയുള്ള മാസങ്ങളുടെ പേരിൽ 2000_jan, 2000_feb എന്നിങ്ങനെ ഫോൾഡറുകൾ ഉണ്ടാക്കണമെന്നു കരുതുക. നൂറ്റി എൺപതു ഫോൾഡറുകളുടേ പേരുകൾ ഒന്നൊന്നായി ടൈപ്പ് ചെയ്യുന്നതിനുപകരം
mkdir {2000..2014}_{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}
എന്നു കൊടുത്താൽ മതിയാകും.
ഇനി 2000 മുതൽ 2014 വരെ നാലു വർഷങ്ങൾ ഇടവിട്ടുള്ളവയാണു വേണ്ടതെങ്കിൽ {2000..2014..4}_{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec} എന്ന് എക്സ്പ്രഷനുപയോഗിക്കാം.
അക്കങ്ങൾക്കു പകരം അക്ഷരങ്ങളിൽ ..4 എന്നു കൊടുത്താൽ നാല് അക്ഷരങ്ങൾ ഇടവിട്ട് പ്രിന്റ് ചെയ്യും. ഉദാ : echo {a..z..4} എന്നത് a e i m q u y എന്നു പ്രിന്റ് ചെയ്യും