• Bash Print Array
    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-662afee3cff7c879772147/] [crayon-662afee3cff86308469313/] Alternatively, we can print the array as follows: [crayon-662afee3cff87984395911/] [crayon-662afee3cff88777897318/] In both examples, […]

  • Bash return String from function
    30 June

    Bash Return String from Function

    Using Substitution Syntax Use substitution syntax represented by $(...) to return string from function in Bash. [crayon-662afee3d6347219004006/] [crayon-662afee3d6351822270801/] You can use local variable as well if you want as below: [crayon-662afee3d6352291119428/] [crayon-662afee3d6354773395658/] 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 […]

  • Bash echo multiple lines
    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 […]

  • PowerShell trim string after character
    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-662afee3d66fe394720900/] [crayon-662afee3d6701348044164/] 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 […]

  • PowerShell find filename by name
    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-662afee3d6928694807782/] [crayon-662afee3d692c223018117/] 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 […]

  • Bash remove blank lines from file
    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 […]

  • PowerShell add days to Date
    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 […]

  • PowerSHell add date to filename
    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-662afee3d802c549530475/] [crayon-662afee3d8036930946179/] The above code is functioning in the following manner: It first sets the $Filename variable to […]

  • PowerShell get last modified file in directory
    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-662afee3d8270240057887/] [crayon-662afee3d8275322543888/] The code uses the Get-ChildItem […]