Awk is used to get a particular pattern in a ouput
you can use this to print a particular pattern
To print the third column in the output using space as the delimiter
awk -F " " '{print $3}'
If you want to print the particular row and a particular column you can use like this
awk -F " " 'NA==3{print $2}'
Monday, May 23, 2011
Wednesday, May 18, 2011
Comparing NULL in C example
You can use the below code for comparing String with NULL in C
char * ff;
if ( ff != NULL ) );
{
printf("value isnot null");
}
else
{
printf ("value is null");
}
Comments in C and C++
In C
valid comments are when text are in between /* .......*/
It can also be used across multiple lines.But it will not support nested comments.
ex:
/* comments */
or
/* First line
Second line */
It can also be used like:
/* comments
* comments
* comments
*/
new C compilers also supports inline comments // . but old compilers may give syntax error.
ex:
int c; // for intializing
C++ supports both type of comments inline comments // and /* ...*/
strcmp and strncmp in C
strcmp function in c
int strcmp(char * str1,char * str2)
strcmp function returns a number eitheir 0, positive integer or negative integer
Return vaues:
positive integer - is returned if string str1 is greater than string str2
0 - if both the strings are equal
negative integer - if string str1 is less than the string str2
In this case comparisons happen using unsigned integers.
for example:
char * i = "hello";
char * j="hello1";
printf("%d",strcmp(i,j));
output will be a negative integer
strncmp in C:
The syntax all are same .but in this case there is an extra argument for setting how many characters you want to compare.
int strncmp(char *str1,char * str2, int );
Functionality all are same.But here int parameter is to set no of characters to compare in two strings.
for example:
char * i = "hello";
char * j="hello1";
printf("%d",strcmp(i,j,4));
output will be 0 as we compare only 4 characters and it is same in both the strings.
Tuesday, May 17, 2011
hosts.allow and hosts.deny in Linux
hosts.allow and hosts.deny files are mainly used for restricting the ssh to th editing your server in which you are
editing the files.
These files are maintained by the TCP wrappers
These are mainly used for securing your server or system from outside acccess.
The way it happens when a outside ip asks for permission to ssh to your system:
1)The Tcp wrapper first checks for entry in /etc/hosts.allow.If a entry is present ,it does not go to the /etc/hosts.deny.
2)If entry is not present ,then it goes for hosts.deny ->if entry is present , the ip is denied
if entry is not present ,the ip is allowed.
If the entry is not present in both hosts.allow and hosts.deny , the entry is allowed.
editing the files.
These files are maintained by the TCP wrappers
These are mainly used for securing your server or system from outside acccess.
The way it happens when a outside ip asks for permission to ssh to your system:
1)The Tcp wrapper first checks for entry in /etc/hosts.allow.If a entry is present ,it does not go to the /etc/hosts.deny.
2)If entry is not present ,then it goes for hosts.deny ->if entry is present , the ip is denied
if entry is not present ,the ip is allowed.
If the entry is not present in both hosts.allow and hosts.deny , the entry is allowed.
Comparators in shell
In case of shell comparison one need to be very careful as one extra space may lead to the code throwing errors
For example :
if [$dd=1]
then
.....statement
fi
This is completely wrong as it will throw a "syntax error near unexpected token near then"
as there are three errors in this:
1)there must be minimum of one space between if and square bracket "["
2)For comparison in shell ,there must be minimum of one space before and after the equal to sign"="
3)minimum of one space needed between 1 and closing bracket
giving more spaces will not cause error to happen.
proper code:
if [ $dd = 1 ]
then
.....statement
fi
Shell assignments:
Ironic in the case of assignments when compared to comparison,is that there should not be any space before and after the equal-to sign("=")
FOR EXAMPLE:
Inside the shell file you provide like this:
gg = 1
This will throw a critical error like "unary operater expected " and "command not found"
So it is must in Shell that the assignments must not have space before and after the "=" sign.
It should be:
gg=1
Checking not-equal condition in Shell:
you can use "-ne" or "!= " can be used for numbers.
you can use "!=" for comparing strings are not equal.
Logical Operators in Shell:
and -a can be used
cond1 -a cond2 - True if both conditions are true.
ex: [ $gg -eq 1 -a $cc -eq 2 ] .Maintain spaces here else you may get " Too many arguments error"
or - o can be used
ex: [ $gg -eq 1 -o $cc -eq 2 ]
Checking files in Shell:
-f somefile True if somefile exists and is an ordinary file.
-d somefile True if somefile exists and is a directory.
-s somefile True if somefile contains data (the size is not zero).
-r somefile True if somefile is readable.
-w somefile True if somefile is writable.
-x somefile True if somefile is executable.
Subscribe to:
Posts (Atom)