Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Tuesday, June 11, 2013

How to use grep command to exclude the lines beginning with a pattern

For instance when reading from a file you want to exclude all the comments i.e. lines beginning with hash sign (#), then use -v switch for grep command:
grep -v "^\#" $FILENAME

Thursday, May 9, 2013

Korn Shell scripting intro

I recently started writing korn shell scripts here and there and below is some useful info on how to get started. I use vi editor for creating files:
vi myscript.ksh
Korn shell scripts usually have extension ksh The first line of the script should always be:
#!/usr/bin/ksh
After the file has been created, one needs to give it execute permissions so that the file becomes runable:
chmod 755 myscript.ksh
Now the script can be executed as follows:
./myscript.ksh
if the script name or path has spaces in it, it needs to be wrapped in double quotes
"C:\My Documents\My Scripts\myscript.ksh"
The escape character for ksh scripts is a (\) backslash. For example if you want to escape a dollar sign ($) inside your script, instead of writing
select * from v$database;
use
select * from v\$database;
(#) pound sign is used for comments and print and echo commands are used to output text to a sceen

Thursday, April 11, 2013

UNIX - clearing out files that are older than 30 days

Useful command for clearing out old files:
find ./* -type f -mtime +30 -exec rm {} \;
The above will clear out files that are older than 30 days in the current directory. find ./* will look at the current directory, grabbing all the files (*), -mtime +30 will specify files that are older than 30 days, and -exec rm {} \ will remove all the files that match the condition.

Wednesday, December 19, 2012

Some useful commands for vi Editor

Command Action
x delete one character
dw delete current word
dd delete current line
D delete all content to the rigght of the cursor
:u undo last command
:q quit editor without saving
:wq save and quit editor
:w write without exit
:[n] goto line [n]
b move backwards one word
i begin inserting text at the current cursor location