#!/bin/bash
################################################################################################
# 比较当前目录下所有文件的最后125行
# 获取当前目录下所有文件(不包括子目录)
files=(*)
# 检查文件数量
if [ ${#files[@]} -lt 2 ]; then
echo "当前目录下文件不足,无法比较"
exit 1
fi
# 为每个文件提取最后125行并保存到临时文件
temp_files=()
for file in "${files[@]}"; do
# 跳过目录
if [ -d "$file" ]; then
continue
fi
temp_file=$(mktemp)
tail -n 125 "$file" > "$temp_file"
temp_files+=("$temp_file")
done
# 检查是否有足够的文件可以比较
if [ ${#temp_files[@]} -lt 2 ]; then
echo "没有足够的文件可以比较"
exit 1
fi
# 使用第一个临时文件作为基准
base_file=${temp_files[0]}
base_name=${files[0]}
# 比较所有其他文件
for i in "${!temp_files[@]}"; do
if [ $i -eq 0 ]; then
continue # 跳过基准文件
fi
current_file=${files[$i]}
temp_file=${temp_files[$i]}
echo "比较 $base_name 和 $current_file 的最后125行..."
diff "$base_file" "$temp_file"
if [ $? -eq 0 ]; then
echo "=== $base_name 和 $current_file 的最后125行相同 ==="
else
echo "!!! $base_name 和 $current_file 的最后125行不同 !!!"
fi
done
# 清理临时文件
for temp_file in "${temp_files[@]}"; do
rm -f "$temp_file"
done
################################################################################################
#!/bin/bash
log_file=ota_pack_$(date "+%Y%m").log
# new_pack=pack_$(date "+%Y%m%d_%H%M%S").datx
LB3_c_0=a1
LB3_c_1=a1
LB4_c_0=a1
LB4_c_1=a1
LB5_c_0=a1
LB5_c_1=a1
LB6_c_0=a1
LB6_c_1=a1
LB3_d_0=a1
LB3_d_1=a1
LB4_d_0=a1
LB4_d_1=a1
LB5_d_0=a1
LB5_d_1=a1
LB6_d_0=a1
LB6_d_1=a1
function signature_format()
{
hash_key=$1
hash_len=${#hash_key}
key_str=""
for (( i=0; i<$hash_len; i+=2 )); do
key_str=$key_str"0x${hash_key:$i:2},"
done
echo "$key_str" | tee -a $log_file
}
function package_produce()
{
pack_num=$#
if [[ $pack_num -lt 1 ]] ; then
return
fi
new_pack=LB
for temp in $@ ;do
if [ -f $temp/aaaaaaaa* ] && [ -f $temp/$temp.datx ] ; then
if [[ -n "$(echo $temp | grep -i _lb3_)" ]] ; then
new_pack=${new_pack}_3
elif [[ -n "$(echo $temp | grep -i _lb4_)" ]] ; then
new_pack=${new_pack}_4
elif [[ -n "$(echo $temp | grep -i _lb5_)" ]] ; then
new_pack=${new_pack}_5
elif [[ -n "$(echo $temp | grep -i _lb6_)" ]] ; then
new_pack=${new_pack}_6
else
echo "$temp : LB Number invalid"
return
fi
if [[ "${temp:0:8}" == "compress" ]] ; then
new_pack=${new_pack}c
elif [[ "${temp:0:5}" == "delta" ]] ; then
new_pack=${new_pack}d
else
echo "$temp : package type invalid"
return
fi
if [[ "${temp: -1}" == "0" ]] ; then
new_pack=${new_pack}0
elif [[ "${temp: -1}" == "1" ]] ; then
new_pack=${new_pack}1
else
echo "$temp : side type (0/1) invalid"
return
fi
else
echo "[dir] $@"
echo "files not found in : $temp"
echo "exit"
return
fi
done
offset=0
new_pack=$new_pack.datx
if [ -f $new_pack ] ; then
rm $new_pack $new_pack.$(date "+%Y%m%d_%H%M%S").bak
fi
echo "======== ======== ======== ========" | tee -a $log_file
echo "$(pwd)" | tee -a $log_file
if [[ $pack_num -gt 1 ]] ; then
echo "[$(date "+%Y-%m-%d %H:%M:%S")] generate $new_pack " | tee -a $log_file
else
echo "[$(date "+%Y-%m-%d %H:%M:%S")]" | tee -a $log_file
fi
for temp in $@ ;do
tmp_size=$(ls -l $temp/$temp.datx | awk '{print $5}')
echo "======== $temp : " | tee -a $log_file
if [[ $pack_num -gt 1 ]] ; then
cat $temp/$temp.datx >> $new_pack
printf "offset : 0x%08X\n" $offset | tee -a $log_file
(( offset = offset + tmp_size ))
fi
datx_size=$(printf "%08X\n" $tmp_size)
echo "size : 0x$datx_size 0x${datx_size:0:2},0x${datx_size:2:2},0x${datx_size:4:2},0x${datx_size:6:2}" | tee -a $log_file
signature_format $(cat $temp/signature*.txt)
done
echo "" | tee -a $log_file
}
# package_produce $LB3_d_0 $LB4_c_0 $LB5_c_0 $LB6_d_0
# package_produce $LB4_c_0 $LB5_c_0
# package_produce $LB3_d_1 $LB4_c_1 $LB5_c_1 $LB6_d_1
package_produce $LB3_c_0 $LB4_c_0 $LB5_c_0 $LB6_c_0
############################################################################################################
# 去掉最后一个字符
string="Hello World!"
new_string=$(echo "$string" | sed 's/.$//') # or # new_string="${string%?}"
echo "$new_string" # 输出: Hello World