Archive

Archive for April, 2012

Printing variables side by side – Part 2

April 20, 2012 Leave a comment

Problem:

You have a for loop and you want to print the results side by side. Echo will not work in this situation.

Solution:

printf

Here is the example with echo.

shell>echo -e "trains\nplanes\nautomobiles" | \
while read tran_mode;
do
echo $tran_mode;
mysql -uUser -pPassword database -N \
 -e"select count(*) from table where value=$tran_mode";
done

trains
0
planes
0
automobiles
0

Here it is with printf

shell>echo -e "trains\nplanes\nautomobiles" | \
while read tran_mode;
do
printf "%s, %s" $tran_mode;
mysql -uUser -pPassword database -N \
 -e"select count(*) from table where value=$tran_mode";
done

trains, 0
planes, 0
automobiles, 0

awk – Printing row totals

April 18, 2012 Leave a comment

Problem:

Had various files with totals that had to be combined/totaled into one file.

From

cars,30,cars,15,cars,5
bikes,0,bikes,0,bikes,6
trains,10,trains,30,trains,15
buses,0,buses,0,buses,0

To

cars,50
bikes,6
trains,55
buses,0

Solution:

I went with awk.


paste -d, file1.txt file2.txt file3.txt  | \
cut -d, -f1,2,4,6  | \
awk -v FS="," 'total=$2+$3+$4+1 {print $1,total-1}'

NB:

Using

awk -v FS="," 'total=$2+$3+$4 {print $1,total}'

Will not return any results that have a zero. So add one to the total then remove it when printing so that you can get the zero counts.

awk -v FS="," 'total=$2+$3+$4+1 {print $1,total-1}'
Categories: awk Tags:

Galaxy Tab screen blank

April 8, 2012 Leave a comment

Problem:

Installed vplayer on the 7″ Galaxy tab. It played the video correctly the first few times. But then out of the blue the screen goes blank. Pressed the power button a few times and I could faintly see the system clock but everything else was unresponsive. Resorted to looking for a solution on google. Fortunately, I found something that works.

Solution:

1. Long press the Volume Up and Power button for a few seconds.

2. It shows a triangle in the middle of the screen with the option to reboot or wipe/cache and the wipe-data/factoryreset. I just wanted to reboot so I pressed the Volume Up key again.

3. Now press the home key on the tab. That acts as the Enter key. Wait for a while and press the Home key again. Your system should now reboot.

Source:

http://forum.xda-developers.com/archive/index.php/t-949794.html