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
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)
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)
- Download latest java from oracle site http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
- 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)
- untar using command 'sudo tar -xzvf jre-7u25-linux-x64.tar.gz -C /usr/java/
- 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/"
- 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
-
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
Monday, June 17, 2013
code complexity tool pmccabe
whenever
we write code, it is advisable to test the complexity of the code we
are writing. This will help in source code maintainability, readability
etc.
The best algorithm to do the same is cyclomatic complexity. (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
One of the utility implementing this algorithm is pmccabe.
This ain't any IDE also! A simple CLI utility.
install:
sudo apt-get install pmccabe
usage:
<username>@<hostname>:~~$ find ./ -name *.c | xargs pmccabe | sort -nr | head -10
49 49 116 361 134 <file>(362):<function>
The first column indicates the complexity score of each of the functions mentioned.
The wiki suggests that the complexity score should be kept below 10, and in inevitable cases, it can go upto 15.
The best algorithm to do the same is cyclomatic complexity. (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
One of the utility implementing this algorithm is pmccabe.
This ain't any IDE also! A simple CLI utility.
install:
sudo apt-get install pmccabe
usage:
<username>@<hostname>:~~$ find ./ -name *.c | xargs pmccabe | sort -nr | head -10
49 49 116 361 134 <file>(362):<function>
The first column indicates the complexity score of each of the functions mentioned.
The wiki suggests that the complexity score should be kept below 10, and in inevitable cases, it can go upto 15.
vlc player, enable en queue(add to playlist) on right click
By default, on double clicking on a song in folder, the song is opened in new vlc player session. There is no "add to playlist" option. To change this settings,
- On the vlc player, go to tools->preferences
- click on 'interface' (default) on the left menu, on the right, click on 'instances'
- check both 'allow only one instance' and 'enqueue when in one instance mode'
Tuesday, June 11, 2013
blogger can't import wordpress posts!
I was on wordpress before. Thought of moving to blogger, as wordpress want me to pay for each and everything more than what they consider 'basic'.
- I went my wordpress dashboard->settings->export
- exported an xml file (selected all as an option, to include posts, tags comments etc)
- Then I created a blogger, went to settings->other->import blog
- my xml files was just in Kbs, nevertheless, the blogger went on taking hours to import
- What I noticed is that it was stuck on first post itself to import. Then I learnt that to import from wordpress to blogger, a conversion is needed.
- So, go to wordpress to blogger convertor and get your xml file converted.
- Try repeating step #3.
- It should work!
Subscribe to:
Posts (Atom)