Monday, September 15, 2025

Sanitize JSON: Blank Out Sensitive Content

jq '
  walk(
    if type == "string" or type == "number" or type == "boolean"
    then "" 
    else . 
    end
  )
' secrets.json

Thursday, August 28, 2025

Extract a portion of a log file based on the starting timestamp

If there are multiple matches, this command takes the last start and the first end, which may not be what you want. If that is acceptable, consider anchoring one line before the start and one after the end to ensure the full range is captured:
sed -n '/^2025-08-28 01:00:04,114/,/^2025-08-28 01:00:08,178/p' /tmp/test.log

Wednesday, August 27, 2025

pbcopy from linux shell

Working across Mac, Windows, and Linux via SSH? Ever wished you could pbcopy from within a remote SSH session? Add this "one-liner" to your ~/.bashrc or ~/.profile:
pbcopy() {
 printf "\033]52;c;%s\033\\" "$(cat | base64 -w0)"
}
If you use tmux you will need a bit more:
pbcopy() {
  if [ -n "$TMUX" ] && command -v tmux >/dev/null 2>&1; then
    # Read stdin into tmux buffer and also copy to system clipboard via OSC 52
    tmux load-buffer -w -
  else
    # Direct OSC 52 for non-tmux shells
    # Portable base64: avoid line wraps
    printf '\033]52;c;%s\007' "$(base64 | tr -d '\n')"
  fi
}

Monday, August 25, 2025

Sanitize your json config before sharing it

jq 'def scrub:
      if type == "object"
      then with_entries(.value |= scrub)
      else empty
      end;
    scrub' config.json

Followers