需要將檔案名稱在某些單字之後切成部分

需要將檔案名稱在某些單字之後切成部分

我如何hhmmss從這樣的文件名中獲取: abcdeProfileList_YYYYMMDDhhmmss.xml我還需要在 hhmmss 之間添加 : 。就像 hh:mm:ss

答案1

for i in *.xml; do TMP=${i%.xml}; echo ${TMP:(-6)};done

答案2

ls abcdeProfileList_YYYYMMDDhhmmss.xml | cut -d '.' -f 1 | grep -o '......$'

但我假設了很多。

你的問題需要更具體。

答案3

echo "abcdeProfileList_YYYYMMDDhhmmss.xml" | awk -F"_" '{print $2}'|awk -F"." '{print $1}'| cut -c 9-14

答案4

假設Bash環境:

jvc@BlueBuilder:~$ filename=abcdeProfileList_YYYYMMDDhhmmss.xml
jvc@BlueBuilder:~$ timetag=`echo "${filename/.xml/}" | cut -f2 -d_`
jvc@BlueBuilder:~$ echo "${timetag:8:2}:${timetag:10:2}:${timetag:12:2}"
hh:mm:ss

如果你有多個檔案 - 再次使用 Bash:

ls -1 *.xml | cut -f1 -d. | cut -f2 -d_ | while read timetag; do 
  echo "${timetag:8:2}:${timetag:10:2}:${timetag:12:2}"; 
done

相關內容