Script(s)

technology as-is

August 15, 2015
by gchandra
0 comments

Linux : Split Name and Extension from filename

If is just filename  (samplefile.txt) then follow these steps.

$ fullname=”samplefile.txt”

$ extension=”${fullname##*.}”

$ filename=”${fullname%.*}”

$ echo $extension

result : txt

$ echo $filename

result : samplefile


 

If filename is part of path  (/usr/gchan/samplefile.txt)

$ fullname =”/usr/gchan/samplefile.txt”

# Remove the path and get only  “samplefile.txt”

$ fullname=”${fullname##*/}”  

$ echo $fullname

result : samplefile.txt

# Now repeat the same steps mentioned above to split the name and extension. If above step is not done, then filename will contain  /usr/gchan/samplefile  instead of  samplefile.

$ extension=”${fullname##*.}”

$ filename=”${fullname%.*}”

 

 

 

September 4, 2014
by gchandra
0 comments

SQLServer : Get Last Businessday of previous month

DECLARE @LastmonLastBusinessDay date, @inputdate date

SET @inputdate = ’05/25/2014′

SELECT @LastmonLastBusinessDay = DATEADD(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@inputdate),0))
– CASE DATENAME(dw,DATEADD(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@inputdate),0)))
WHEN ‘SUNDAY’ THEN 2
WHEN ‘SATURDAY’ THEN 1
ELSE 0
END
print @LastmonLastBusinessDay

August 12, 2014
by gchandra
0 comments

Special or Random characters on PuTTy screen

Recently I have been noticing some weird special characters on my PuTTy screen.  There was no pattern to it. It will appear all of a sudden.

Its so annoying when you are working on a script.

ex: ^[[28~

Reason : To keep my windows active from locking, I had installed an application called ‘caffeine’ .  Caffeine periodically sends a key stroke to my session active. Whenever caffeine sends a keystroke and if my PuTTy is active it a special weird character gets displayed on screen.

Solution : Set the status of Caffeine to InActive when using PuTTy and it solves the problem.

 

March 17, 2014
by gchandra
0 comments

How to kill or terminate a frozen windows task manager

Here is a simple command line statement to kill frozen windows task manager.

START – RUN – CMD (make sure you are running it as Administrator)

C:>taskkill /F /FI “WindowTitle eq Windows*”

Taskkill – Command

/F – Forcefully terminate the process(es)

/FI – Filter

“WindowsTitle” – valid filter

eq – valid operator


Note:
C:> taskkill /? to learn about more valid filters and valid operators regarding taskkill command.

Happy Scripting !!

December 1, 2013
by gchandra
0 comments

Mac : How to convert video_ts to ISO (FREE)

Its easy to convert  DVD folders to ISO.

Mac offers  hdiutil command line tool which can be used for to achieve the same.

Open Terminal Window  (GO > Utilities > Terminal)

Type the following command

$  hdiutil makehybrid -udf -udf-volume-name  <<YourDVDVolumeName>> \
-o <<yourname.iso>>  /folderpath/parentdirectoryofvideo_ts

Note: If video_ts resides on   /user/user1/download/movie1/video_ts

above command will look like

hdiutil makehybrid -udf -udf-volume-name  movie1  \
-o movie1.iso  /user/user1/download/movie1

In few minutes .iso file will be ready.

By default the output iso file will be stored on  /user/user1  folder.

 

August 12, 2013
by gchandra
0 comments

SQLServer Delete Duplicate Rows

Deleting duplicate rows in SQLServer is very simple.

Example : Check this table let me call it as Sample, order number 1,2 & 3  have identical values. Now we need to delete the duplicate rows.

Duplicate-01

 

Step 1 : Insert another column in table Sample called  Dup of type Integer.

Step 2 : Execute this Query  (uses Common Table Expression)

WITH DUP_CTE AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY ORDERNO,Name,COST ORDER BY ORDERNO) AS DupRank FROM Sample
)

UPDATE DUP_CTE  SET Dup = DupRank

Now the table looks like this

Deuplicate-02

 

Step 3 : Delete all the rows where Dup greater than 1

DELETE Sample Where Dup > 1

Duplicate-03

 

Step 4 : If  new column Dup is not needed drop it from Table.

Easy right !!