Wednesday, April 28, 2010

Function in shell script

Declare the function before calling it.# Function to get password
functionGetpwd()
{
echo "Please provide $USR database password"
read PWORD
echo "Connecting to Database"
}

Call the function
 functionGetpwd

Monday, April 26, 2010

Convert from EBCDIC to ASCII

dd if=InputFile of=OutputFile conv=ascii

The above command will convert EBCDIC InputFile to ASCII OutputFile. If you omit of=OutputFile, the output fill go to stdout.
If you want to use stdin, remove if=InputFile. Use control+D to terminate input.

I kept forgetting the dd command, hence this post, which it seems is versatile. It can be used to convert from lowercase or uppercase or convert only n bytes or blocks at a time. Further, I can combine the conversion keywords. e.g.

dd if=testE.dat conv=ebcdic,lcase

Friday, April 9, 2010

Remove Hyperlinks from excel worksheets

Sub RemoveHyperlink()
'
' Remove Hyperlink from each and every cell of you worksheet
'
'
Dim TotalCols as Integer
Dim TotalRows as Integer

For k = 1 To TotalCols
For i = 1 To TotalRows
Cells(i, k).Select
Selection.Hyperlinks.Delete
Next
Next
End Sub

Thursday, April 8, 2010

Zip and Unzip Unix

unzip filename.zip
will unzip the file

unzip -l filename.zip
will list the content of the archive

unzip -d chosenDir filename.zip
will unzip the the file in your chosenDir

zip filename.zip addNewfile.txt
will addNewfile.txt to the existing archive filename.zip


#

Sunday, February 28, 2010

Global Variables

If you want to access same variable in multiple functions, you declare it as global var1 in your program.

Global variables can be read from all the functions but if you need to modify them, you need to declare them again in that function. Why? So that you don't inadvertently cause cascading effect. It's a preventive measure.

But then how are we able to read the variables w/o declaring them? It's a friendly feature. Python looks for local variables and if they are not found; it looks for any global variable. Since you're just trying to read the variable; it won't (hopefully) be a costly mistake.

Friday, February 26, 2010

Merge excel cell values ; Retain Boundaries

I'm working with excel workbooks for more than 6 hours a day. I needed a quick way to consolidate values of selected cells of a column in the top most row.
e.g.
To merge values of cells 41 to 45 of column B, select the cells and hit the macro. All the values will be consolidated in cell 41.

Sub concate_cell_values()
' This macro consolidates the values
' of the "selected" cells in the top most cell
' Respects cell boundaries

Dim Rng1 As Range
Dim op As String
Dim col, ro As Integer
col = 0
ro = 0

Set Rng1 = Selection

For Each cell In Rng1
cell.Activate
If col = 0 Then
col = ActiveCell.Column
ro = ActiveCell.Row
End If
op = op & cell & " "
Next cell

Cells(ro, col).Value = Trim(op)

End Sub

Tuesday, February 23, 2010