• ansible,  Korn Shell / Bash,  Security

    Keeping an Eye on SSH Keys: Easily Review authorized_keys with awk

    Hello fellow Admins! Who hasn’t been there? The ~/.ssh/authorized_keys file is a crucial component for the security of your servers. But sometimes, especially when many keys are stored or very long keys are in use, the file can quickly become overwhelming. Getting a quick overview without endlessly scrolling through lengthy character strings is truly golden. That’s precisely why I have a small but powerful tip for you: an awk script that makes your authorized_keys more readable by shortening the SSH keys to a manageable length, without losing any vital information. Why is this useful? The awk Magic (Ansible-Aware!) This awk script shortens the actual SSH keys (the second column) to…

  • Korn Shell / Bash,  PowerShell,  Shell Scripting,  Windows Bash

    đź’ˇHow to Extract Specific Lines from a File: sed, awk, head/tail, grep, and with powershell

    In the command line, it’s often necessary to extract only specific lines from a text file – whether it’s a single line or a range of lines. Fortunately, Bash offers several powerful tools for this. In this blog post, I’ll show you the most common methods using sed, awk, head/tail, and grep. Additionally, I will demonstrate an option when using PowerShell. Extracting Lines with sed sed (Stream EDitor) is a classic for text manipulation in the shell and is excellent for selectively outputting line ranges.Output a Single Line (e.g., Line 102)To output a specific line, such as line 102, you use the p command (print) in combination with the -n…

  • Korn Shell / Bash,  Shell Scripting

    Mehrfache Einträge in großen Konfigurationsdateien oder Protokollen finden (Linux/Unix Lösung)

    Oft vermutet man in größeren Protokolldateien oder Konfigurationsdateien mehrfach vorhandene Einträge. Diese sollen schnell ermittelt und bei Bedarf entfernt werden. Unter Linux gibt es das Werkzeug uniq. Der Parameter --count gibt alle Zeilen aus und die Häufigkeit Ihres Auftretens in der ersten Spalte. Es funktioniert nur nicht so intuitiv, wie erwartet. Ich versuche es an einem Beispiel: uniq –count console.log 1 <?xml version=”1.0″ encoding=”UTF-8″ ?> 1 <Protokollzeile xxxyyyzzz > Diese Datei hat offensichtlich zwei Zeilen insgesamt und beide unterscheiden sich. Das ist im Moment nicht sehr hilfreich. Daher verdoppele ich die Datei und fĂĽge eine einzeln vorkommende Zeile hinzu: cat console.log >> consoleDup.log cat console.log >> consoleDup.log echo “Eine abweichende…

  • Shell Scripting

    awk – Ă„ndern der GroĂźschreibung in Kleinbuchstaben

    Die Funktion tolower in einem awk Skript ändert Grossbuchstaben in Kleinbuchstaben: awk '{ print tolower($0) }' Die Funktion toupper in einem awk Skript ändert Grossbuchstaben in Kleinbuchstaben: awk '{ print toupper($0) }' Beispiel für AWK Funktion tolower In diesem Beispiel soll das erste Feld in Kleinbuchstaben ausgegeben werden. echo ABCDEF GHIJK | awk '{ print tolower($1), $2 }' abcdef GHIJK Beispiel für AWK Funktion toupper In diesem Beispiel soll das erste Feld in Kleinbuchstaben ausgegeben werden. echo abcdef ghijk | awk '{ print toupper($1), $2 }' ABCDEF ghijk

  • Shell Scripting

    Leerzeilen aus einer ASCII Datei entfernen

    Um bei einer Dateianzeige die leeren Zeilen zu entfernen, gibt es verschiedene Möglichkeiten. Ich stelle hier 2 Methoden vor. Variante 1 verwendet den Unix Befehl grep grep -v ^$ Variante 2 verwender das Kommando awk. awk ' NF>0 ' Beispiel fĂĽr grep Das verwendete Pattern setzt sich aus einem ^ fĂĽr den Zeilenanfang und einem $ fĂĽr das Zeilenende zusammen. Leerzeilen setzen sich ja, bei genauer Betrachtung, aus einem Zeilenanfang sofort gefolgt von einem Zeilenende zusammen. echo "ABCDEF \n\n GHIJK \n\n\nXYZ" | grep -v ^$ ABCDEF GHIJK XYZ Beispiel fĂĽr awk Beim awk wird die interne Variable NF verwendet. NF enth%auml;lt die Anzahl der Felder der aktuellen Zeile. Leerzeilen haben…