Pages

Tuesday, July 16, 2013

count number of blank lines in a file using grep



To count number of blank lines in a file, we use following grep expression.

$grep -c '^$' filename

=> this will try to extract lines starting and ending with nothing in between.

Saturday, July 13, 2013

how to debug bash shell script

 Unlike C/C++ applications, wherein you will you have to printf messages to debug, there is an easier and more detailed way of debugging shell scripts, specially in bash.

In your shell script, you can add

set -x

at the top of the script, this will make bash to print each command line it parse in your shell script, plus the result of the command as well.

Doing this permanently enable tracing, until you remove it or put "set +x" which is the default.

If you just want to see how it goes once, you can run your script "myscript.sh", try

$ bash -x myscript.sh

output looks like

+ var1=hi
+ var2='how are you'
++ paste hi how are you
paste: hi: No such file or directory
+ var3=
+ echo

"+" means, the sublevel of the command from the main shell script. i.e one + indicates the exact line of command as written in shell script, 2 +s indicate another command within the line of code you have written inside the script.

There is another, lesser debug info method.

$ bash -v myscript.sh

output looks like

#!/bin/bash
var1="hi"
var2="how are you"
var3=`paste $var1 $var2`
paste $var1 $var2
paste: hi: No such file or directory
echo $var3

This will just echo each line of the script as it parses, plus errors or echos from script if any.

Upgrade Java Runtime (JRE) on Debin/Ubuntu

Its high time you upgrade your JRE on your linux, as any version before Java 7 update 11 has serious security flaws. 

Firefox, by default blocks java based on the version you have installed. It means it doesn't allow you to run any java application using these security-issue-ridden java versions.

But, not the same with other browsers or your OS. You got to update it immediately.

NOTE: openjdk jre is also similar to oracle java, hence you can expect same issues with open jdk too. Until you get an update on openjdk, I suggest you use oracle java, well it is not too complex to install oracle java as it looks like on the surface.

Here is how to be done: (OS: Ubuntu)


  1. Download latest java from oracle site http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
  2. if you are using 32 bit linux(most likely intel, x86 arch), choose the right file to download(rpm type for redhat based, .gz for debian based)
  3. untar using command 'sudo tar -xzvf jre-7u25-linux-x64.tar.gz -C /usr/java/
  4. To enable this java on Firefox, create soft link for a lib libnpjp2.so from your java directory to firefox plugin directory. It looks something like this:                                                                 "sudo ln -s /usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so /usr/lib/firefox/plugins/"
  5. to verfiy, restart firefox, go to "about:plugins" in address bar,  see if you have following information: "

    Java Plug-in 1.7.0_25

    File: libnpjp2.so
    Path: /usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so "

    that's it, you are upgraded!

    For google-chrome, you don't have to do anything if you have untarred the jre under /usr/java. To verify, restart your chrome, go to 

    chrome://plugins/

    Look for 

    Java(TM) Download Critical Security Update
    Java plug-in for NPAPI-based browsers.
    Name:Java Plug-in 1.7.0_25
    Description:Java plug-in for NPAPI-based browsers.
    Version:
    Location:/usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so

    (don't forget to remove older versions of java)

Saturday, July 6, 2013

convert images to pdf


to convert one or multiple images to pdf file, use the command

$convert scan_*.jpg scanned_docs.pdf

convert command comes with package imagemagick