Sum of all Array Elements in Linux

In this Blog, Sharing the code to add all elements of an Array using shell scripting. a =(1 2 3 4) ## Array of 4 Elementsi=0len=${#a[@]} ## It gives the length of an Arraysum=0 ## Setting sum variable to value 0while [ $i -lt $len ]dosum=$((${a[i]}+$sum))i=$(( $i + 1))doneecho $sum

Search Element In An Array in Linux

In this blog, Sharing the code to Search an Element in an Array using Shell scripting. a =(1 2 3 4) ## Array of 4 Elementsi=0x=2 ##x is the element which need to be searched in an Arraylen=${#a[@]} ## It gives the length of an Arraylen1=$(( $len – 1 )) ##len1 is used to display if element is not present in an array.while [ $i -lt $len ]doif [[ ${a[i]} -eq $x ]]thenecho $x is presentbreakfiif [[ $i -eq $len1 ]]then echo $x is not presentfii=$(( $i + 1))done

Generate GBs of file using one small file in linux

In this blog, I will share the shell script which will generate/create a big file (GBs of Data). Consider a small file which has very less records (say 3 records). See the below SS of the sample Data. Using above file we will write code to append data of this file to another file multiple times which results in a big output file. echo “COL1|COL2″ > linux_copy_.txtfor i in {1..100}docat linux.txt |tail -n+2 >> linux_copy.txtdone First line of code is about creating another file “linux_copy.txt” and adding header to this…

Perform Arithmetic Operations On Two Files

In this Blog , we will cover how to apply sum ,multiply or subtract operator on two files each having one field and same number of records. Consider the data in each file as below. Below is the Shell script which will multiply row by row from above two files and put the output in another file. arr1=()for line in cat linux.txt | tail -n+2doarr1+=(“$line”)donearr1_1=()for line in cat linux_1.txt | tail -n+2doarr1_1+=(“$line”)doneLenOfArr= ${#arr1[@]}touch newfile.txtecho “COL1” > newfile.txta=0while [ $a -le $((LenOfArr-1)) ]; do let ans=${arr1[a]}*${arr1_1[a]}; echo $ans >> newfile.txt; a=$((…

DIFFERENCE BETWEEN POWERSHELL AND SHELL SCRIPTING – PART3

This blog is the continuation of my previous blog , where I have explained the difference between PowerShell and Shell Scripting through 5 different scenarios. Here , in this Blog , I will take few more commands and will show the difference between them. Consider one file in windows and one file in Linux with same Data. Print selected column of a fileWindows use below commands. Need to mention what all columns are required.$headers=@(“COL1″”COL2”) Use import csv command to display data for above mentioned headers.Import-Csv -Path .\PowerShell_Scripting.txt -Delimiter ‘|’ |…

Difference Between PowerShell and Shell Scripting – PART2

This blog is the continuation of my previous Blog, where I have explained the difference between PowerShell and Shell Scripting through 5 different scenarios. Here , in this Blog , I will take 5 more different commands and will show the difference between them.Consider one file in windows and one file in Linux with same Data. Clear the content of a fileWindows use “Clear-Content”Clear-Content .\PowerShell_Scripting.txt Linux uses “>” symbol to truncate or removing content of a file.>Linuxfile.txt Copy a file from one Location to anotherWindows uses “Copy-Item” command to remove…

Remove trailing spaces and zero from a string in SQL-Server

In this blog, I will discuss about “How to remove trailing spaces and zeros from a string without using any trim function”.I have written a procedure for the same. In one of my blog where I have shared the code for removing the leading zeros and spaces, here as well, code is almost the same. CREATE PROCEDURE [dbo].[RmTrailingZerosSpcs] (@String VARCHAR(500) )asBEGINDECLARE @output VARCHAR(100) = ”;DECLARE @prev CHAR(1) = ”;DECLARE @c CHAR(1) = ”;DECLARE @i int = 1;DECLARE @len int;DECLARE @len_zeros int =0;declare @reversestring varchar(200)select @reversestring= reverse(@String)SET @len = len(@reversestring);WHILE(@i <=…

Remove Leading Zeros and Spaces In SQL-SERVER

In this Blog, I will discuss about “How to remove Leading Zeros and Spaces from a value in SQL server”. I have written procedure for it . See the below code . CREATE PROCEDURE [dbo].[RmLeadZerosSpcs] (@String VARCHAR(500) )asBEGINDECLARE @output VARCHAR(100) = ”;DECLARE @prev CHAR(1) = ”;DECLARE @c CHAR(1) = ”;DECLARE @i int = 1;DECLARE @len int;DECLARE @len_zeros int =0;SET @len = len(@String);WHILE(@i <= @len) begin SET @c = SUBSTRING(@String, @i, 1); IF @c=’0′ or @c=’ ‘ BEGIN SET @len_zeros=len(@c)+@i SET @output = substring(@String,@len_zeros, @len); SET @i = @i + 1;…

Difference between Unix and PowerShell Commands

In this Blog, I will demonstrate the difference between Unix and PowerShell Commands. It will help all coders who works on Scripting Languages.Consider the one file in windows and one file in Linux with same data.See the below Image for the same. Find the Total Number of Records in a file . Linux uses “cat” and “wc -l” commandcat LinuxScripting.txt | wc -l Windows “Get-Content” and “Measure-Object” command. $File_count=Get-Content PowerShell_Scripting.txt |Measure-Object Read first n lines of a file Linux uses “cat” and “head” command.cat LinuxScripting.txt | head -3 Windows uses…

ORACLE INTERVIEW QUESTIONS

In this blog, I gathered few Interview Questions asked on Oracle Database. It will be very useful for 2-4 years of Experience IT Professionals.1. When we should use Materialized view and non materialized view.2. Difference between Ref cursor and sys ref cursor.3. What are the different types of TRIGGERS.4. Difference between SUBSTRING and INSTRING function.5. If a query is taking more time to display results, What’s first step will you perform to check this issue.6. Exceptional handling in Oracle procedure.7. Name PSEUDO columns in Oracle.8. Difference between Schema and User…