Skip to main content
add nullglob
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12

If you have bash4+, here is one way using mapfile aka readarray

#!/usr/bin/env bash

shopt -s nullglob

rawfiles=(*.mp4)
mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n)
mapfile -t playlistfile < <(sort -n playlist.m3u8)

for i in "${!files[@]}"; do
   mv -v  "${files[$i]}" "${playlistfile[$i]}"
done

Output on Linux

renamed '1.mp4' -> '1- Introduction-OxIDLw0M-m0.mp4'
renamed '2 .mp4' -> '2 - How React Works-pKYiKbf7sP0.mp4'
renamed '3 .mp4' -> '3 - React Setup (with CDN)-SAX6RMEFVM4.mp4'
renamed '4 .mp4' -> '4 - React Components-Fis_Q3rkgtM.mp4'
renamed '5 .mp4' -> '5 - State-yuN4EMjR4K4.mp4'
renamed '6 .mp4' -> '6 - React Dev Tools--XQ2zCdxw0I.mp4'
renamed '7 .mp4' -> '7 - DOM Events--ZB8I2PmiOw.mp4'
renamed '8 .mp4' -> '8 - Changing State (and '\''this'\'')-XJzDF9bj368.mp4'
renamed '9 .mp4' -> '9 - Intro to Forms-BVbdZ1133JU.mp4'
renamed '10 .mp4' -> '10 - Create React App-5QwNCX3UbXc.mp4'

Here is the oneliner

rawfiles=(*.mp4); mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n); mapfile -t playlistfile < <( sort -n playlist.m3u8); for i in "${!files[@]}"; do  mv -v  "${files[$i]}" "${playlistfile[$i]}"; done

If you have bash4+, here is one way using mapfile aka readarray

#!/usr/bin/env bash

rawfiles=(*.mp4)
mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n)
mapfile -t playlistfile < <(sort -n playlist.m3u8)

for i in "${!files[@]}"; do
   mv -v  "${files[$i]}" "${playlistfile[$i]}"
done

Output on Linux

renamed '1.mp4' -> '1- Introduction-OxIDLw0M-m0.mp4'
renamed '2 .mp4' -> '2 - How React Works-pKYiKbf7sP0.mp4'
renamed '3 .mp4' -> '3 - React Setup (with CDN)-SAX6RMEFVM4.mp4'
renamed '4 .mp4' -> '4 - React Components-Fis_Q3rkgtM.mp4'
renamed '5 .mp4' -> '5 - State-yuN4EMjR4K4.mp4'
renamed '6 .mp4' -> '6 - React Dev Tools--XQ2zCdxw0I.mp4'
renamed '7 .mp4' -> '7 - DOM Events--ZB8I2PmiOw.mp4'
renamed '8 .mp4' -> '8 - Changing State (and '\''this'\'')-XJzDF9bj368.mp4'
renamed '9 .mp4' -> '9 - Intro to Forms-BVbdZ1133JU.mp4'
renamed '10 .mp4' -> '10 - Create React App-5QwNCX3UbXc.mp4'

Here is the oneliner

rawfiles=(*.mp4); mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n); mapfile -t playlistfile < <( sort -n playlist.m3u8); for i in "${!files[@]}"; do  mv -v  "${files[$i]}" "${playlistfile[$i]}"; done

If you have bash4+, here is one way using mapfile aka readarray

#!/usr/bin/env bash

shopt -s nullglob

rawfiles=(*.mp4)
mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n)
mapfile -t playlistfile < <(sort -n playlist.m3u8)

for i in "${!files[@]}"; do
   mv -v  "${files[$i]}" "${playlistfile[$i]}"
done

Output on Linux

renamed '1.mp4' -> '1- Introduction-OxIDLw0M-m0.mp4'
renamed '2 .mp4' -> '2 - How React Works-pKYiKbf7sP0.mp4'
renamed '3 .mp4' -> '3 - React Setup (with CDN)-SAX6RMEFVM4.mp4'
renamed '4 .mp4' -> '4 - React Components-Fis_Q3rkgtM.mp4'
renamed '5 .mp4' -> '5 - State-yuN4EMjR4K4.mp4'
renamed '6 .mp4' -> '6 - React Dev Tools--XQ2zCdxw0I.mp4'
renamed '7 .mp4' -> '7 - DOM Events--ZB8I2PmiOw.mp4'
renamed '8 .mp4' -> '8 - Changing State (and '\''this'\'')-XJzDF9bj368.mp4'
renamed '9 .mp4' -> '9 - Intro to Forms-BVbdZ1133JU.mp4'
renamed '10 .mp4' -> '10 - Create React App-5QwNCX3UbXc.mp4'

Here is the oneliner

rawfiles=(*.mp4); mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n); mapfile -t playlistfile < <( sort -n playlist.m3u8); for i in "${!files[@]}"; do  mv -v  "${files[$i]}" "${playlistfile[$i]}"; done
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12

If you have bash4+, here is one way using mapfile aka readarray

#!/usr/bin/env bash

rawfiles=(*.mp4)
mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n)
mapfile -t playlistfile < <(sort -n playlist.m3u8)

for i in "${!files[@]}"; do
   mv -v  "${files[$i]}" "${playlistfile[$i]}"
done

Output on Linux

renamed '1.mp4' -> '1- Introduction-OxIDLw0M-m0.mp4'
renamed '2 .mp4' -> '2 - How React Works-pKYiKbf7sP0.mp4'
renamed '3 .mp4' -> '3 - React Setup (with CDN)-SAX6RMEFVM4.mp4'
renamed '4 .mp4' -> '4 - React Components-Fis_Q3rkgtM.mp4'
renamed '5 .mp4' -> '5 - State-yuN4EMjR4K4.mp4'
renamed '6 .mp4' -> '6 - React Dev Tools--XQ2zCdxw0I.mp4'
renamed '7 .mp4' -> '7 - DOM Events--ZB8I2PmiOw.mp4'
renamed '8 .mp4' -> '8 - Changing State (and '\''this'\'')-XJzDF9bj368.mp4'
renamed '9 .mp4' -> '9 - Intro to Forms-BVbdZ1133JU.mp4'
renamed '10 .mp4' -> '10 - Create React App-5QwNCX3UbXc.mp4'

Here is the oneliner

rawfiles=(*.mp4); mapfile -t files < <(printf '%s\n' "${rawfiles[@]}"| sort -n); mapfile -t playlistfile < <( sort -n playlist.m3u8); for i in "${!files[@]}"; do  mv -v  "${files[$i]}" "${playlistfile[$i]}"; done