Wednesday, July 20, 2016

Difference between awk and cut command?

cut:  takes a single character in -d as the field delimiter (the default being TAB), and every single occurrence of that character starts a new field. 



awk:  however, is more flexible. The separator is in the FS variable and can be an empty string (every input character makes a separate field), a single character, or a regular expression. The special case of a single space character (the default) means to split on any sequence of whitespace. Also, awk suppresses leading whitespace by default.

Examples: 

% echo "All is well" | cut -f 2 -d ' '
is

%echo "All  is  well" | cut -f 2 -d ' '


% echo " All is well" | cut -f 2 -d ' '
All


% echo "All is well" | awk '{print $2}'
is

% echo "All  is  well" |  awk '{print $2}'
is

% echo " All is well" | awk '{print $2}'
is





How to check if a port is occupied or not?


Monday, July 18, 2016

Difference between the perl functions: chop and chomp?

chomp: Deletes only new line character "$/   (or) \n" (input record separator or new line character) at                the end of the line.


chop: Deletes the last character irrespective what it is.