Tuesday, December 22, 2020

Stripping spaces from filenames

 Here is a handy script for stripping spaces from filenames in a directory and all of its subdirectories:


#!/bin/bash


function strip_spaces_from_files {

  for i in *

  do

    newfilename=$(echo $i | tr -s ' ' | tr ' ' '_')

    if [ -e "$newfilename" ]

    then

      echo "$newfilename does not contain any spaces"

    else

      echo "stripping spaces from $newfilename"

      mv "$i" "$newfilename"

    fi

  done

}


INITIALDIR=$PWD

echo "Stripping spaces from current directory $INITIALDIR"

strip_spaces_from_files


echo "Stripping spaces from sub directories"


for subd in $(find ./ -type d)

do

  strippingdot=$(echo "${subd}"|sed 's/^..//')

  echo "switching to directory $INITIALDIR/$strippingdot"

  cd $INITIALDIR/$strippingdot

  echo "stripping spaces"

  strip_spaces_from_files

  echo "going back to initial directory $INITIALDIR"

  cd $INITIALDIR/

done

Friday, December 11, 2020

Validating yaml with python

 python -c 'import yaml, sys; yaml.safe_load(sys.stdin)' < url-monitor-extension-config.yml