我有一个将数据输出到 txt 文件的代码,但我想从每个文件名的输出中删除 ./
代码如下
#!/bin/bash
# fill with more extensions or have it as a cmd line arg
TYPES=( mov mp4 avi mp3 wma)
DIR=$1
# Create a regex of the extensions for the find command
echo "Available Media Files in Directory"
TYPES_RE="\\("${TYPES[1]}
for t in "${TYPES[@]:1:${#TYPES[*]}}"; do
TYPES_RE="${TYPES_RE}\\|${t}"
done
TYPES_RE="${TYPES_RE}\\)"
# Set the field seperator to newline instead of space
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# Generate output from path and size using: `stat -c "%s" filepath`
OUTPUT=""
for f in `find ${DIR} -type f -regex ".*\.${TYPES_RE}"`; do
OUTPUT=`echo ${f}`";"$OUTPUT
done
# Reset IFS
IFS=$SAVEIFS
# Reverse numeric sort the output and replace ; with \n for printing
echo $OUTPUT | tr ';' '\n' | sed 's/.*/"&"/' | sort -nr >playlist.txt
结果是:
"./You Da One.mp3"
"./Wiz Khalifa Roll Up.mp4"
"./Vybz Kartel neva get a gal.mp3"
"./Tyga Rack City.mp4"
"./Tyga Lap Dance.mp4"
"./Travis Porter Make It Rain.mp4"
"./Travis Porter ft. Tyga Ayy Ladies.mp4"
"./Snoop Dogg feat. Wiz Khalifa Bruno Mars Young Wild & Free.mp4"
"./Shot Caller.mp3"
"./Chris Brown - Your Body.mp4"
"./Chris Brown Turn Up The Music.mp4"
需要从每个文件中删除 ./
谢谢