SED: Insert/append data to particular line number

Sed is a powerful tool to do some text manipulations in a file. We already covered some basic SED stuff. http://www.linuxnix.com/2012/04/sedsteam-editor-explained-detail-linuxunix.html In this post we will see one simple use case of SED. I have a requirement where I have to insert a new line with some data at a particular line. We can achieve it(…)

SED: Delete a matched line from a file

This is a small post on how to delete a line from a file when it matched some criteria. We can use many tools and languages like sed, awk, grep, python, perl, ruby etc. In this post we specifically use SED which is by default installed in Linux. SED is a powerful tool which is(…)

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.(…)