- 论坛徽章:
- 0
|
本帖最后由 liu-shaobo 于 2012-12-07 11:30 编辑
请教shell中路径的问题,我一个脚本想对比两个文件版本生成补丁,不过遇到一个问题,
文件有3层目录的,也有4层目录的,当执行脚本2时,y_old_file_path,y_new_file_path,y_as_file_path就会出现问题,脚本和文件如下,y开头的路径对应4层目录,如果放在一个脚本里面,不知道大家有什么好办法
ufile.log文件格式:- file/0/2/v1.log file/1/2/v2.log
- file/0/2/22/v1.log file/1/2/25/v2.log
复制代码 脚本1- #!/bin/bash
- old_file_path=$1/$2/$3
- new_file_path=$5/$6/$7
- as_file_path=path/$new_file_path
- if [ ! -d $as_file_path ]
- then
- mkdir -p $as_file_path
- fi
- y_old_file_path=$1/$2/$3/$4
- y_new_file_path=$6/$7/$8/$9
- y_as_file_path=path/$y_new_file_path
- if [ ! -d $y_as_file_path ]
- then
- mkdir -p $y_as_file_path
- fi
- if [ $# == 8 ]
- then
- diff -Nu $old_file_path/$4 $new_file_path/$8 > $as_file_path/$8.path
- else
- diff -Nu $y_old_file_path/$5 $y_new_file_path/${10} > $y_as_file_path/${10}.path
- fi
复制代码 脚本2- awk -F"[/ ]" '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10}' ufile.log |while read line
- do
- echo "${line}" |xargs 脚本1
- done
复制代码 |
|