Author: Arpit Mandliya
- 19 March
Print Object in PowerShell
Print Object’s Properties in Powershell In PowerShell, an object is a data structure that contains properties and methods. An object is essentially an instance of a .NET class and can be created using the New-Object cmdlet. PowerShell objects are used extensively in PowerShell scripting. For example, many cmdlets return objects as output, which can be […]
- 17 March
Python Sleep Milliseconds(ms) with examples
💡 Outline You can use time.sleep() method to sleep for milliseconds in Python. If you want to delay python program by 500 ms, then you need to pass 0.5 as parameter to sleep method. [crayon-67695b5fa8ddd016759826/] 1. Introduction Sometimes, the execution of a program needs to be suspended or paused for a given time. This is […]
- 15 March
Check if String Starts with Another String in Bash
Using Regex Operator with if statement To check if string starts with another string in bash, use the regex operator =~ with if statement. [crayon-67695b5fa8ee8504537299/] [crayon-67695b5fa8eeb730029033/] In this script, the =~ operator compares the string variable to the regular expression. In addition, this operator tests whether the string on the left side matches the regular […]
- 15 March
PowerShell – Find String in File
1. Overview Searching for strings in text files is a common task in PowerShell, used in scenarios like log file analysis and configuration file searches. This article explores various methods for finding strings in files, including both case-sensitive and case-insensitive approaches. 2. Introduction to Problem Statement Let’s consider a log file named server.log: [crayon-67695b5fa90a2095246323/] Our […]
- 13 March
Find Position of Character in String in PowerShell
Using IndexOf() Method Use the IndexOf() to find the position of character in string in PowerShell. indexOf() method returns index of first occurrence of character in String. [crayon-67695b5fa92b2031461982/] [crayon-67695b5fa92b5275470011/] In the above code, the output indicates that the input string is Hello, world! and the position of the comma character in the string is 5. […]
- 13 March
Get Random Number Between 1 and 100 in Bash
Using $RANDOM Variable Use the $RANDOM variable to generate a random number between 1 and 100 in Bash. [crayon-67695b5fa93b1007006047/] [crayon-67695b5fa93b3114498856/] The above code generates a random integer number between 1 to 100 and prints it on the bash console. How? The $RANDOM generated a random integer between 0 and 32767. Then, we used the %100 […]
- 13 March
Create Empty Array in Python
Creating an Empty Array in Python Before moving towards various solutions for creating an empty array in Python, we must understand what an empty array means. It means a collection of items with a particular data type containing no items or elements. We can use different ways to create an empty one-dimensional, two-dimensional and multi-dimensional […]
- 13 March
Wait for Command to Finish in PowerShell
Using Start-Process Cmdlet Use Start-Process with the -Wait parameter to wait for the command to finish. [crayon-67695b5fa9801354770250/] OUTPUT: In the above output, we can see that the command waits until the file explorer is opened. To do that, we used Start-Process with the -Wait parameter. The Start-Process cmdlet is used to start one or multiple […]
- 13 March
Check if Array Contains Element in PowerShell
1. Overview In this article, we will see different ways to check if array contains element in PowerShell using -contains operator, Contains() method, Where-Object cmdlet, -in operator, indexOf() method, and LINQ. 2. Introduction to Problem Statement We are given an array and element. Our goal is to check if array contains the element. For instance, […]