Skip to content

Instantly share code, notes, and snippets.

@uuklanger
Last active August 18, 2021 02:46
Show Gist options
  • Select an option

  • Save uuklanger/eb234cc03e71a9364ece0fb31c62cf47 to your computer and use it in GitHub Desktop.

Select an option

Save uuklanger/eb234cc03e71a9364ece0fb31c62cf47 to your computer and use it in GitHub Desktop.

Revisions

  1. uuklanger revised this gist Aug 18, 2021. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions helpful_shell_commands.md
    Original file line number Diff line number Diff line change
    @@ -60,4 +60,27 @@ else
    fi
    ```

    ## Fix Jetbrains Rider Console Log

    When you copy/paste console logs from Rider, they end up with a newline where you have a word wrap. To fix this, the following command can be adapted. In this example, we are expecting that each log entry ends in a ']' and starts with a date/time. In one case some lines did end with a ']' but where not complete. Those had "Batch: [`GUID`]" at the end so they are treated as a special case.

    ```bash
    klanger@laptop:~/logs$ cat Rider_RAW.log | \
    grep -v "^NewWorld" | \
    grep -v "^$" | \
    sed ':a;/[a-zA-Z0-9]$/{N;s/\n//;ba}'| \
    sed ':a;/-$/{N;s/\n//;ba}'| \
    sed ':a;/[\:\[]$/{N;s/\n//;ba}' |
    sed ':a;/Batch\: \[[a-z0-9\-]*\]$/{N;s/\n//;ba}'
    ```

    The goal of the above regex sed statements do the following:

    1. Filter out any line starting with NewWorld
    2. Filter out blank lines
    3. Any line ENDING with a a-z, A-Z, or 0-9 should be combined with next line
    4. Any line ENDING with a "-" should be combined with next line
    5. Any line ENDING with ":" or "[" should be combined with next line
    6. Any line ENDING with "Batch: [xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx]" where "x" could be a-z, A-Z, 0-9, or "-". Lines like this should be combined with the next line.

    ### END
  2. uuklanger revised this gist Jun 18, 2021. 1 changed file with 43 additions and 1 deletion.
    44 changes: 43 additions & 1 deletion helpful_shell_commands.md
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,46 @@ cat 20210614.raw |awk 'NF'

    ```
    tr -d '\r' < a.txt > b.txt
    ```
    ```

    ## Create a good SSH KEy

    ```
    ssh-keygen -t rsa -m PEM -b 4096 -C "mylogin@HOST"
    ```

    ## Rename a list of files to be lowercase

    The ls -1 is the selector of which files are impacted so be careful.

    ```
    for f in `ls -1`; do mv -v "$f" "`echo $f | tr '[A-Z]' '[a-z]'`"; done
    ```

    ## Create a missing directory

    Say you want a sub directory called `output_data`

    ```
    cd dt_modules/sample
    pwd
    if [ ! -d "output_data" ]; then
    mkdir output_data
    fi
    ```

    ## Determine if a file is Zero length

    You might have a file that exists but has nothing in it.

    ```
    file_length=$(cat ${json_content_object_file} | wc -l)
    if [[ ${file_length} -eq 0 ]]; then
    echo "WARNING: NO DATA FOR "${json_content_object_file}
    else
    echo "INFO : "${json_content_object_file}" has "${file_length}" characters in it"
    fi
    ```

    ### END
  3. uuklanger revised this gist Jun 18, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion helpful_shell_commands.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ cat boring.json | python3 -m json.tool > pretty.json
    cat 20210614.raw |awk 'NF'
    ```

    ## Use Translate to fix this
    ## Convert DOS to UNIX Text Formatting

    ```
    tr -d '\r' < a.txt > b.txt
  4. uuklanger revised this gist Jun 18, 2021. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions helpful_shell_commands.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,21 @@
    # Format JSON output as pretty
    # Helpful Command Cheet Sheet

    These are commands that I forget regularly and need to look up.

    ## Format JSON output as pretty

    ```
    cat boring.json | python3 -m json.tool > pretty.json
    ```

    # Remove blank line from a file
    ## Remove blank line from a file

    ```
    cat 20210614.raw |awk 'NF'
    ```

    ## Use Translate to fix this

    ```
    tr -d '\r' < a.txt > b.txt
    ```
  5. uuklanger created this gist Jun 18, 2021.
    12 changes: 12 additions & 0 deletions helpful_shell_commands.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # Format JSON output as pretty

    ```
    cat boring.json | python3 -m json.tool > pretty.json
    ```

    # Remove blank line from a file

    ```
    cat 20210614.raw |awk 'NF'
    ```