Saturday, June 27, 2015

initial setup of .bashrc file and .vimrc

C coders initial setup of .bashrc file and .vimrc for small project

For small projects we can add some alias in .bashrc file as below :-
Add below lines for cscope,ctag, and git setup.
 
alias bcscope='find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" > cscope.files'
alias creatctag='ctags `find . -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp"`'
alias documnetviewer='evince';
alias gitsetup='git init;git add *;git commit -am "Initial";echo -e "*.o\n*.ko" > .gitignore'
For .vimrc file need to change below line. 

.vimrc file is a file in home directory from where vi or vim reads some initial setting

set nu           
set hlsearch
set incsearch
set ic
set cursorline


set nu   :- Show line number
set nonu :- Hide line number
set hlsearch :- Set Highlight searching
Screenshot for hlsearch










set incsearch :- Set incremental search
set ic :- Set ignore case
set noic :- Set no ignore case
set cursorline :- Enable horizontal cursor line in vi editor.
Cursor line showing.
 





Note :- For comment out any setting in .vimrc file use " in starting of line

Monday, August 31, 2009

Accessing database Using Shell Script

Here i m going to tell u how can u access the database (mysql,Oracle ) using shell script in linux..

for mysql..

u need to install mysql on your linux distros..

after that as usual write a shell script to access database in user interactive mode..

running script example is...

#!/bin/bash
1 read -p "enter mysql user name:" name
2 stty -echo #echo off
3 read -p "enter mysql passwd :" password
4 stty echo #echo on
5 mysql -u $name -p$password<<END
6 use databasename;
7 select * from tablename
8 END

it asks user for mysql user name and password..then may asks for some pattern,input to search in database and finish with the desired result to the user.

NOTE: If there is no user name and password set for mysql..then skip first for lines of script and replace fifth line with

mysql <<END

also note that there is no space between -p and password provided by the user.



For Oracle10g XE(Express Edition) :


you need to install Oracle10g XE on your linux distros..

you may refer this link to installing on ubuntu..

if you are ready with your installation..
after that as usual write a shell script to access database in user interactive mode..

https://help.ubuntu.com/community/Oracle10g

running script example is...

#!/bin/bash
1 read -p "enter oracle user name:" name
2 stty -echo #echo off
3 read -p "enter mysql passwd :" password
4 stty echo #echo on
5 sqlplus $name/$password<<END
6 select * from tablename;
7 END

it asks user for oracle user name ( generally system )and password..then may asks for some pattern,input to search in database and finish with the desired result to the user.

Thank you............

Finding common text or difference in two files

Here I want to discuss the command or single liners for finding the words
common in two given text files or their difference .Difference what mean here is that such words which are present in one file but not in other just analogous to the set operation difference.

now coming to the procedure..

Although there is inbuilt command in unix for doing this, but i has the limitation that..

1.)input files must be sorted.
2.)it gives the lines common to both not words..(not sure..u can check it)

the command is comm file1 file1

it's output is 3 column output..
1st column gives the file1-file2
2nd column gives the file2-file1
3rd column gives the common of file1 and file2

you can get only what u want by suppressing the option such as

using comm -12 file1 file2

it gives the lines common to both files.

CAUTION: It Requires the input file must contain the lines in sorted order.otherwise it will give unpredictable output.

now my answer is..

using cat and grep command...

grep -o "`cat file2`" file1
or
cat file1 | grep -o "`cat file2`"

2nd one is better in case of searching lines.
as it gives output as line wise.first one gives all matching lines in a single line.

string within quote makes content of file2 as searching pattern for file1.
-o option is set for printing only the matching word as output.

if u want the common lines in the two files use -x option of grep.

for finding the difference use -v option .
for finding the words ignoring the case use -i option of grep.

now, If u don't want to use cat in creating pattern.u can directly use -f option of grep command to provide pattern from a file.

grep -of file1 file2

is same as above command .all other option follows with it.

NOTE : one thing u should keep in mind while using -f option is that it must be last option. as above..
e.g. grep -fo file1 file2 will not work for the same.

It overcomes all the limitations of the comm command in unix.
i.e.
1.)It don't require input files in sorted order.
2.)matching words can be found not only lines.

I hope u will like it..

Feel free to comment ..if u feel any difficulty in understanding..

Thanks..
Enjoy Scripting............

Thursday, July 30, 2009

Problems...

hii Guyss..
This post is not related to shell scripting..
but i wanna say u in his post that..if u have any problem in shell scripting..
Plzzz let us know ..we contributor of this blog will try to answer ur problem
Attach ur problem as comment to this post......

Qs are welcome.....

Thank you...

Wednesday, July 29, 2009

How can I see the O/P in a another Terminal?

If I wrote a script in a new Terminal. Then after I want to see the output of
that script in an another terminal. How Can I See that?

I have solution but if any one have direct command for it pl suggest me


You can find the name of the other terminal

i.e by
tty command you can see the name of the terminal

now you redirect the output to that terminal

tty
/dev/pts/0

tty
/dev/pts/1

echo "amit khatri">/dev/pts/1
you see the result on New terminal

Thursday, July 16, 2009

see the difference...

hii frnds..
now a interesting thing about the buffer used at the terminal on unix..

suppose the following C code is running on any unix system..

$ cat test.c

#include
int main()
{
printf("Hello\n");
if(fork()==0)
printf("World\n");
return 0;
}

$ gcc test.c
$ ./a.out
Hello
World
$ ./a.out>test
Hello
World
Hello
$

why output is different in two cases..

It is the difference between the buffer used for terminal standard output and the other ordinary file..if output is to be be shown on the terminal line buffer is used i.e. when it encounters '\n' it flushes out buffer content..but in case of other file buffer content is flushed out only when it is full..in the above code..that's why when child is run Hello is retained there in buffer and Hello is printed twice in case when output is redirected to file.But when it runs directly Hello is printed only one time..as there is '/n' which flushes out the buffer content.So Hello is printed only when parent is running..when '\n' is ommited..output will be same in both cases.Try it yourself.

Thank you...

Sunday, June 14, 2009

vowel count in a file ..........

A script count the number of occurance of vowels in particular file

i.e how Many times a vowel come in the file ....

grep -io [aeiouAeIOU] |sort|uniq -c