PFOTD: Python enumerate() function examples

Today our python built-in function is enumerate() which is very much useful to generate iterator element along with index. Need of enumerate() function in Python: Some times we require to generate a sequence of elements in a list or tuple along with their index. Let us see an example. I have a list L1=[23, 56, ‘surendra’, ‘test’,(…)

How to sort SQL table by column?

Today I come across with a complex sql query requirement where I have to filter a table on a column entry and then sort according to date. The SQL language have some inbuilt keywords like ORDER to sort out this type of issues. Let use have below table for our practice purpose For ascending order(…)

Learn python try and except statements with examples

The try and except statements in python helps us to mitigate exception errors with a meaning full way. To understand why we require try and except statements we should know how python handles execution and syntax errors. There are two types of errors in Python 1)Syntax errors 2)Exception errors Syntax errors occur when there is a(…)

Difference between Python range and xrange functions?

Python have two builtin functions which are useful to generate a sequence of numbers. These two functions are useful when you want to do iteration using for loop. Though both of the functions do same work like generating sequence but the way work is totally different. In this post we will see syntax, how to use(…)

PFOTD: Python bin(), oct() and hex() functions for base conversions

Today our python built-in function(s) are bin(), oct() and hex() which are useful for converting any type of number like negative, integer and large to their respective base numbers. Need of bin(), oct() and hex() function in Python: When we are doing some math work it is require to convert different types of numbers to other number types and do calculations.(…)

PFOTD: Python abs() function examples

Today our python built-in function is abs() which is useful for converting any type of number like complex, negative, integer and large to its absolute number.  Need of abs() function in Python: When we are doing some math work it is require to convert different types of numbers to their absolute value and do calculations.(…)

SQL query: Search for multiple values in same field

Some times if we want to update a table or query a table for multiple values in a single column we have to run our simple sql query multiple times. Suppose if you want to get an element value in a column of a table you normally run a select command as shown below. SELECT *(…)

AWK ignore case(CAPS/lower) while patten search

Recently I come across a requirement to search for lines in a given file/files where the search term is mix of capital letters and small letters. Normally when we search with awk it search exactly what we try to search but not ignoring case. We can use grep to accomplish this task as sown below.(…)

Sed/paste/AWK/Perl: Merge or Join two lines

In this post we will see how to merge lines in a given file or standard output.  sed 'N;s/\n/ /' filename paste -d " " – – < filename Related posts: how to join lines in a file in Linux? Linux script/command to display lines ends with .(dot) and ;(semicolon) Linux/Unix shell script to number(…)

Shell scripting: Convert a string from lowercase to uppercase

The linux shell has provided us with many hidden gems. Some of things are string manipulation with out using external commands like SED/AWK. In this post we will see how to convert a string from lower case to upper and upper case to lower by using string manipulation techniques and tr command. String manipulation for lower(…)