143 Linux 批量修改文件夹所有文件指定内容并还原文件修改时间
#!/bin/bash function log_date() { # 获取文件的原始修改时间,并写入同级文件夹下cos_log_date.txt文件 if [ -d "$1" ]; then ( cd $1 ls -al --time-style '+%Y%m%d%H%M.%S' |grep "cos.log" |awk -F " " '{print $6}' > ../../cos_log_date.txt ) fi }function log_sed() { if [ -d "$1" ]; then ( cd $1 local log_file=$(ls -l |grep "cos.log" |awk -F " " '{print $9}') local log_num=$(echo "${log_file}" |wc -l) local log_index=1
if [ ${log_num} -ge 1 ]; then for log_cos in $(echo "${log_file}"); do if [ -s ${log_cos} ]; then # 遍历日志并修改对应日志内容 sed -i 's/Blending\ Path\ Failure.*/robot\ axis\ number\ is\ :6/g' ${log_cos} sed -i 's/\[E/\[I/g' ${log_cos} sed -i 's/\[W/\[I/g' ${log_cos} # 修改日志后,把文件原始的修改时间重新变更 local date_c=$(sed -n "${log_index}p" ../../cos_log_date.txt) touch -t ${date_c} ${log_cos} echo -e "${log_index} | ${date_c} ${log_cos} done\n" fi let log_index++ done fi ) fi }
log_date $1 log_sed $1 标签:文件,cos,log,修改,sed,date,143 From: https://www.cnblogs.com/jianqiang-1/p/16988965.html