• Bash sort CSV by column
    14 July

    Sort CSV by Column in Bash

    Bash Sort CSV by Column Using sort Command Use bash’s sort command to sort the CSV file by column. [crayon-663cf48e4a62d495016159/] [crayon-663cf48e4a639992652718/] [crayon-663cf48e4a63a176807206/] In this example, the sort command is used to sort the myFile.csv file by column. Here, the -t parameter is used to specify the field separator, which is , in the above case. […]

  • Bash write variable to file
    14 July

    Bash Write Variable to File

    Using echo Command Use the echo command with redirection operator (>) to write variable to file in Bash. [crayon-663cf48e4ae78617754066/] [crayon-663cf48e4ae9e819503102/] Use the echo command with the append operator (>>) to append a variable to the end of the specified file in Bash. [crayon-663cf48e4ae9f818566224/] [crayon-663cf48e4aea0743258627/] Use the echo command with the append operator (>>) to append […]

  • Bash Append to Array
    14 July

    Bash Append to Array

    Using Shorthand Operator Use the Shorthand operator to append one element to an array in Bash. [crayon-663cf48e4b2a9077740272/] [crayon-663cf48e4b2b2975072704/] First, we declared an array (my_array) with three initial elements element1, element2, and element3. Then, we used the shorthand operator (+=) to append the new_element to the end of an array. Finally, we used the echo command […]

  • Bash get curl response code
    05 July

    Bash Get Curl Response Code

    Using cUrl command with -w, -s and -o options For Get Method Use the -w or --write-out option in combination with the %{http_code} format specifier to get curl response code in Bash for get method. [crayon-663cf48e4b5de436886843/] [crayon-663cf48e4b5e6327304622/] We can also rewrite it into more verbose format in case you need for better understanding. [crayon-663cf48e4b5e7456806319/] In […]

  • sed remove line containing string
    03 July

    sed Remove Line Containing String

    Using sed Command Read the provided text file and remove lines containing string using sed command. We will not modify the input file (file.txt) but display the output on the Bash console. We can use -i option in case we want to modify input file [crayon-663cf48e4b818039306552/] [crayon-663cf48e4b81f546409955/] [crayon-663cf48e4b821382378502/] Let’s break down command to understand it […]

  • awk remove first column
    03 July

    awk Remove First Column

    Using awk command with sub() method Use the awk command with sub() method to remove the first column from the given CSV file (inputFile.csv) in Bash. We will not update the input file but display the output on the Bash console. [crayon-663cf48e4badf063880887/] [crayon-663cf48e4bae6776325952/] [crayon-663cf48e4bae8238781361/] Here we used $1="" to replace first column with empty string […]

  • Bash remove last line from file
    01 July

    Remove Last Line from File in Bash

    1. Overview In Unix-like environments, especially in scripting and programming with Bash, there might be scenarios where we need to remove the last line from a file. This operation is typical in data processing, log file management, and scripting. 2. Introduction to Problem Statement Imagine we have a text file named test.txt containing the following […]

  • Bash remove spaces from String
    01 July

    Bash Remove Spaces from String

    Using sed Command Use the sed command to remove spaces from string without updating the original variable in Bash. [crayon-663cf48e4c227180124653/] [crayon-663cf48e4c22e647939655/] First, we stored the string value in the var variable. Then, we piped it to the sed command, a stream editor performing operations on the text streams. In the above case, we used it […]

  • 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. [crayon-663cf48e4c714297590393/] [crayon-663cf48e4c71b993950128/] Using Backslash Character Use a backslash character (\) to escape a single quote in […]