Friday, February 20, 2015

What is .profile in Unix

Environment is defined by environment variables.

 Which are set by:

·         The system
·         Some by you
·         Some by the shell
·         Any program that loads another program.

 Environment variables are set without using $ sign but while accessing them we use $sign as prefix. These variables retain their values until we come out shell.

When you login to the system, the shell undergoes a phase called initialization to set up various environments. This is usually a two-step process that involves the shell reading the following files:
·         /etc/profile
·         profile
The process is as follows:
1.    The shell checks to see whether the file /etc/profile exists.
2.    If it exists, the shell reads it. Otherwise, this file is skipped. No error message is displayed.
3.    The shell checks to see whether the file .profile exists in your home directory. Your home directory is the directory that you start out in after you log in.
4.    If it exists, the shell reads it; otherwise, the shell skips it. No error message is displayed.
As soon as both of these files have been read, the shell displays a prompt:
$
This is the prompt where you can enter commands in order to have them execute.

Usually the type of terminal you are using is automatically configured by either the login or getty programs. Sometimes, the auto configuration process guesses your terminal incorrectly.
If your terminal is set incorrectly, the output of commands might look strange, or you might not be able to interact with the shell properly.

for more information http://www.tutorialspoint.com/unix/unix-environment.htm



Friday, February 13, 2015

Awk script to read and write to file

Awk script to read from a file and format the string and write the out in another file.

Input file

ABC;def;ghi;jkl
Mno;pqr;stu;vwx

Awk script

#!/bin/ksh

FILENAME= $1

awk 'BEGIN {FS=";"} {printf " update table set column= '\''%s'\'' where column= something \n" , $2 > "output file.txt"} ' $FILENAME

…..............

Run script
Scriptname inputfilename