Bash strings handling Examples

Vijay

Saturday, April 20, 2024  /  0 Comments

Bash strings handling Examples

Recently I found some difficulty performing some string handling in shell script especially in bash. Even If I google for any string handling in shell script, I am bombarded  with a lot of stuff but with tools like awk, perl, sed, python but very rarely in bash. So I thought it would be good to have useful string handling...

Debugging a PL/SQL Stored procedure

Vijay

Wednesday, March 15, 2017  /  46 Comments

Debugging a PL/SQL Stored procedure

Normally while working on PL/SQL stored procedures , we use DBMS_TRACE for knowing about the values of various variables and put some print statements. This looks fine until you use your stored procedures on cli. But Lets assume your stored procedure is being called from a different process,lets say a c++ or a Java process. In this case you...

Seach a string and replace consequent lines in perl

Vijay

Tuesday, March 07, 2017  /  0 Comments

Seach a string and replace consequent lines in perl

Lets say I have C/C++  file which has some pattern in the line at the start. I also know that there will be 2 lines following the line that will match my pattern. I want to remove these three lines and add a new line which has a different string which is nothing but I want to replace a...

Look ahead and Look behind in perl

Vijay

Thursday, June 05, 2014  /  2 Comments

Look ahead and Look behind in perl

With the look-ahead and look-behind constructs ,you can "roll your own" zero-width assertions to fit your needs. You can look forward or backward in the string being processed, and you can require that a pattern match succeed (positive assertion) or fail (negative assertion) there. Every extended pattern is written as a parenthetical group with a question mark as the...

Split a string by anything other than spaces

Vijay

Monday, May 19, 2014  /  0 Comments

Split a string by anything other than spaces

Have you ever tried this. Dont go on writing big perl code for this. Here's a simple solution for this. my @arr=split /\S+/,$str; where $str is your string \s obviously matches a white space character. But \S matches a non white space character. So \S+ matches atleast one non white space character....

Find and replace a string in c++

Vijay

Monday, May 19, 2014  /  0 Comments

Find and replace a string in c++

This can be handy many a times when you are working on a C++ application. There is a no direct method in the standard to do the same except when you are using a boost library. Below is a simple function that I use regularly in my applications which comes in handy for me all the time template<class T>...

Inserting lines in a file using Perl

Vijay

Wednesday, May 14, 2014  /  0 Comments

Inserting lines in a file using Perl

I have input file that look's like : cellIdentity="42901" cellIdentity="42902" cellIdentity="42903" cellIdentity="52904" Numbers inside the quotes can be anything. The output needed is original line followed by the copy of same line except the last digit of the number should be a series of 5,6,7. So the output should look like below: cellIdentity="42901" cellIdentity="42905" cellIdentity="42902" cellIdentity="42906" cellIdentity="42903" cellIdentity="42907" cellIdentity="52904"...

Comparing two files using awk - An assignement

Vijay

Monday, May 12, 2014  /  0 Comments

Comparing two files using awk - An assignement

This is an awk assignment given to one of my friend. Its quite challenging. We have two files: File1:(List of companies) Joe's Garage Pip Co Utility Muffin Research Kitchen File2:(List of payments and dues of the companies in File1) Pip Co $20.13 due Pip Co $20.3 due Utility Muffin Research Kitchen $2.56 due Utility Muffin Research Kitchen 2.56 due...

Joining lines using Awk

Vijay

Friday, May 02, 2014  /  1 Comments

Joining lines using Awk

Let's say I have a input file which looks like below: Apr 24 2014; is; a; sample; ; Jun 24 2014 123; may 25 2014; is; b; sample; ; Dec 21 2014 987 I want to merge 6 lines at a time. Which means my output should look like: Apr 24 2014;is;a;sample;;Jun 24 2014 123 may 25 2014;is;b;sample;;Dec 21...

Iterating a string through each character

Vijay

Tuesday, April 29, 2014  /  0 Comments

Iterating a string through each character

In general if there is a need for us to iterate though a string character by character, then we normally split the string using a statement like: @chars=split("",$var); Now after the array is created we iterate through that array.But an easy way of doing this in Perl without creating an array is : while ($var =~ /(.)/sg) { my...