Bash
 25 July 25 July- Return Array from Function in Bash- Bash cannot return values, whether a single value or an array, but it can return a status (the same as other programs). However, there are multiple turnarounds that we can use to return an array from a function. Let’s explore them below. Using nameref Feature To return the entire array from a function in Bash: […] 
 25 July 25 July- Format Date to yyyymmdd in Bash- Using date Command Use the date command to format the date to yyyymmdd in Bash. [crayon-690463327b555239118654/] [crayon-690463327b55a164514542/] In the above example, the bash date command is used to get the current date with the format specifier '%Y%m%d' to specify the date format. In Bash, the date command is used to retrieve the date and time […] 
 24 July 24 July- Get Last Word in Each Line in Bash- Using awk Command Use the awk command to get the last word of each line from a file in Bash. [crayon-690463327bb05042383225/] [crayon-690463327bb0b214715549/] [crayon-690463327bb0d374241823/] We use the awk command, a powerful text-processing tool allowing you to process and manipulate structured data. The awk command operated each line individually and performed action based on the predefined patterns […] 
 24 July 24 July- Exit Code of Last Command in Bash- Every command we run successfully or unsuccessfully in Bash leaves a particular code behind, which we call an exit code or exit status. We use this code to analyze the last command in Bash. Using $? Variable Use shell variable, $?, to get the exit code of the last-run command in Bash. [crayon-690463327c2a2188580859/] [crayon-690463327c2a8575710647/] We […] 
 24 July 24 July- Get Output from Python Script in Bash- Using Substitution Syntax Use Substitution Syntax ($(...)) to get output from a Python script and store it in a Bash variable. [crayon-690463327ca58010153573/] [crayon-690463327ca5c874635630/] [crayon-690463327ca5e226409254/] We used the command substitution syntax,$(command), to capture the output of the Python script (my_script.py) in a Bash variable (result). Here, the command was python my_script.py, where a Python interpreter executed […] 
 18 July 18 July- Get Everything After Character in Bash- Using Parameter Expansion Use parameter expansion to get everything after character in Bash. [crayon-690463327ce3f047807205/] [crayon-690463327ce43551480595/] First, we set the string variable with a string type value; then, we initialised the delimiter variable with a space character (" "). The delimiter variable contained the character, after which we wanted to extract the remaining portion of the […] 
 18 July 18 July- Get Text Between Two Strings in Bash- 1. Overview In scripting and programming, extracting specific portions of text from larger strings or files is a common task. In this article, we will see different ways to get text between two String using grep, awk, sed, and bash parameter expansion. 2. Introduction to Problem Statement We are given a String, and we need […] 
 18 July 18 July- sed Remove Leading and Trailing Whitespace- Using sed Command with Substitutions Use the sed command with multiple substitutions to remove leading and trailing whitespaces from a single-line string in Bash. [crayon-690463327d3d1362653798/] [crayon-690463327d3d5623650999/] First, we created a variable named str and set its value to a string value which contained leading and trailing whitespaces. Then, we piped the echo $str command to […] 
 17 July 17 July- Print Every nth Line from File in Bash- Using awk Command Use the awk command to print every nth line from file in Bash. [crayon-690463327d59d117149857/] [crayon-690463327d5a0635002516/] [crayon-690463327d5a1946330264/] [crayon-690463327d5a2864961827/] In this example, the awk command gets every 4th line from the file test.txt. Here, the file variable contains the file name from where you want to retrieve the lines. Then, the user is prompted […] 
