[kwlug-disc] Regular Expression to Match Movie Titles and Year and Ignore the rest.
    William Park 
    opengeometry at yahoo.ca
       
    Sun Jan  5 18:32:48 EST 2025
    
    
  
On 2025-01-05 05:01, John Driezen wrote:
> for moviefile in "$@"
> do
If reading from command arguments, then you can just do
     for moviefile; do
>      echo $moviefile | while IFS=. read -a x; do
Better to quote the file, in case you have crazy filenames.
     echo "$moviefile" | ...
>           y=
>           skip=0
>           for i in "${x[@]}"; do
>              case $i in
>                   201[0-9]) y+=" ($i)" ;;
>                   [0-9]*p) y+="-$i" ; skip=1 ;;
>                   avi) y+=".$i" ;;
>                   mkv) y+=".$i" ;;
>                   mp4) y+=".$i" ;;
>                   srt) y+=".$i" ;;
>                   webp) y+=".$i" ;;
You can compact these 5 lines into one line.
     avi|mkv|mp4|srt|webp) y+=".$i" ;;
>                   *) if [[ skip -eq 0 ]]; then y+="${y:+ }$i"; fi ;;
>               esac
>           done
>           echo "Renaming $moviefile as $y"
>           #mv $moviefile "$y"
>      done
> done
    
    
More information about the kwlug-disc
mailing list