• Bash escape single quotes
    01 July

    Bash Escape Single Quote

    In this tutorial, we will see how to escape single quote in Bash. There are multiple ways to escape single quote in Bash. Let’s go through them. Using Double Quotes Use double quotes to escape single quote in Bash. echo "I'm escaping a single quote. Again, I'm doing it." I'm escaping a single quote. Again, […]

  • 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. fruits=("Apple" "Orange" "Banana" "Melon") echo "${fruits[*]}" Apple Orange Banana Melon Alternatively, we can print the […]

  • 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. function return_string(){ echo "Welcome to Java2Blog" } str=$(return_string) echo "$str" Welcome to Java2Blog You can use local variable as well if you want as below: function return_string(){ local local_str_var="Java2Blog" echo "Welcome to $local_str_var" } str=$(return_string) echo "$str" Welcome 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. $string = "Hi! Welcome to Java2Blog! Let's learn." $newString = ($string.Split("!"))[0] Write-Output $newString Hi We declared and initialized the $string variable with "Hi! Welcome to Java2Blog! Let's learn." value. Next, we chained the Split() method […]

  • 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. Get-ChildItem -Path "E:\Test" -Filter "file*" Directory: E:\Test Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 4/25/2023 7:22 AM File -a---- 3/10/2023 12:42 AM 33629 file - Copy.doc -a---- 3/11/2023 […]

  • 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 $Filename = "C:\Test1\File1.txt" $newFilename = "C:\Test1\File1_$(Get-Date -Format yyyy-MM-dd).txt" Rename-Item -Path $Filename -NewName $newFilename Write-Host "New filename: $newFilename" New […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.