Author: Arpit Mandliya
- 30 June
Bash Print Array
Bash Print Array [ Entire array] There are multiple ways to print array in Bash; let’s learn them below. Use echo with Parameter Expansion Use the echo command with parameter expansion syntax to print the array on the Bash console. [crayon-6767b6742c3f4808988116/] [crayon-6767b6742c3fe435647710/] Alternatively, we can print the array as follows: [crayon-6767b6742c3ff374792573/] [crayon-6767b6742c400702395592/] In both examples, […]
- 30 June
Bash Return String from Function
Using Substitution Syntax Use substitution syntax represented by $(...) to return string from function in Bash. [crayon-6767b6742c960370610901/] [crayon-6767b6742c964536382268/] You can use local variable as well if you want as below: [crayon-6767b6742c965456157679/] [crayon-6767b6742c966810709474/] In this example, the return_string() function initialized a local variable named local_str_var with the "Java2Blog" value. Then, we used an echo command to […]
- 30 June
Echo Multiple Lines in Bash
1. Overview In this article, we will see how to echo multiple lines, primarily using the echo command in various forms. Additionally, we will look at alternative methods like printf and here documents. 2. Introduction to Problem Statement Our goal is to print multiple lines with various options. The output of every method will be […]
- 29 June
PowerShell Trim String After Character
Using Split()Method Use the Split() method to trim the string after the first occurrence of the specified character in PowerShell. [crayon-6767b6742cc5c835330131/] [crayon-6767b6742cc5f413114580/] We declared and initialized the $string variable with "Hi! Welcome to Java2Blog! Let's learn." value. Next, we chained the Split() method with the $string variable to split the $string into an array based […]
- 29 June
PowerShell Find File by Name
Using Get-ChildItem Cmdlet Use the Get-ChildItem cmdlet with -Path and -Filter parameters to find the specified files and directories in the given path in PowerShell. [crayon-6767b6742ce1b154488071/] [crayon-6767b6742ce1d420519701/] The Get-ChildItem retrieves items and child items from one or multiple paths (locations). The -Path parameter is used to specify one or multiple paths to locations; we can […]
- 29 June
Bash Remove Blank Lines from File
We can use any of the below commands if we are required to write the output to a new file. But, we can only use sed and perl commands if instructed to remove blank lines and lines containing whitespace characters and store the updated content in the original file. Using grep Command Use the grep […]
- 28 June
PowerShell Add Days to Date
Before we start, knowing how dates are stored in PowerShell is essential. Dates are stored as DateTime, which contains both a date and a time. The dates are in the MM/DD/YYYY format. Let’s continue learning different ways to add days to date in PowerShell. Using AddDays() Method Use the AddDays() method to add days to […]
- 24 June
PowerShell Add Date to Filename
if you don’t want to rename the file and just want to change in string format, you can directly jump to join-path section. Using Rename-Item Cmdlet Use the -Rename-Item cmdlet to add date to file in PowerShell [crayon-6767b6742d42a073197862/] [crayon-6767b6742d42f188866985/] The above code is functioning in the following manner: It first sets the $Filename variable to […]
- 24 June
PowerShell Get Last Modified File in Directory
For this article, our working directory will be C:\Test1 containing two files named File1.txt and File2.txt. Using Get-ChildItem along with Sort-Object Cmdlet Use the Get-ChildItem cmdlet with Sort-Object` cmdlet to get last modified file in directory in PowerShell. Sort-Object cmdlet will sort the File object by LastWriteTime property. [crayon-6767b6742d5ee155107840/] [crayon-6767b6742d5f2632492855/] The code uses the Get-ChildItem […]