#!/bin/bash

if [ $# -eq 1 ]; then dirpath='$1' else dirpath='.' fi

if [ -d '$dirpath' ]; then cd '$dirpath' elif [ -f '$dirpath' ]; then cd "$(dirname '$dirpath')" else echo '错误: 目录或文件不存在: $dirpath' exit 1 fi

find . -name '*.log' -type f -print0 | while IFS= read -r -d '' file; do identifier=$(awk -F 'product name is ' 'NF > 1 {print $2; exit}' '$file') if [ -n '$identifier' ]; then mkdir -p '$identifier' base_filename=$(basename '$file' .log) new_file='$identifier/${base_filename}.log' i=1 while [ -e '$new_file' ]; do new_file='$identifier/${base_filename}_${i}.log' i=$((i+1)) done mv '$file' './$new_file' fi done

find . -depth -type d -empty -delete

Bash 脚本:根据日志文件内容整理文件到对应目录

原文地址: https://www.cveoy.top/t/topic/ntt4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录