Tuesday, June 1, 2021

sed - Add a line to all files


#below inserts a line at 1st row with the content "Added new line using sed " in all the files in the path

for i in *; do sed -i '1s/^/Added new line using sed \n/' $i; done


#below inserts a line at 3rd row with the content "Added new line using sed " in all the files in the path

for i in *; do sed -i '3s/^/Added new line using sed \n/' $i; done

Friday, April 2, 2021

DBeaver Not Responding in macOS

Not quite often but sometimes when either DBeaver or your macOS decides to frustrate you (particularly when you are already frustrated with the work 😉) then you will see DBeaver not starting up with just a spinning rainbow wheel forever. 

In The Activity Monitor, it says DBeaver not responding!!!

Force Quit DBeaver and navigate to this folder:

/Users/schanna/Library/DBeaverData/workspace6/.metadata/.plugins/org.eclipse.e4.workbench

and remove the file: workbench.xmi 

schanna@schanna org.eclipse.e4.workbench % rm workbench.xmi 

Now, you should be back to business.

Tuesday, August 25, 2020

Split a word based on case sensitive...

Received data like "AetnaMercyCareRBHA" in one of our records and showing this data in the reports is quite doesn't readable. 

So, the ask is to display the value like "Aetna Mercy Care RBHA" instead.

This is in Snowflake:

select regexp_replace(regexp_replace('AetnaMercyCareRBHA', '([A-Z])', ' \\1'), '([A-Z])( )', '\\1') ;

Note that there is space before escape character in the inner regexp like ' \\1' and space within the paranethesis in the outer regexp like ( ).

The above simple regexp_replace does the trick. 

Inner regexp_replace divides the word with space whenever there is an uppercase letter.

Outer regexp_replace removes the space between upper case letters eg., "R B H A" to "RBHA"