1:遍历文件夹下面所有文件,并输出到path.path文件中
#!/bin/bash
function getdir(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
getdir $dir_or_file
else
echo $dir_or_file >> path.path
fi
done
}
root_dir="./"
getdir $root_dir
2:提取文件中包含某字段的一行
#!bin/bash
word="opencv_similar_result"
cat ./path.path | while read line
do
#echo $line
if [[ $line == *$word* ]]
then
echo $line
cat $line | while read value
do
echo $value
a=`echo $value | awk '{print $6}'` #将输出的值赋给某变量,这样就可以继续进行操作
if [ $a -gt 0 ]; then
echo $line >> result.txt
echo $value >> result.txt
fi
echo $a
done
fi
sleep 0.05
done
3:判断参数
#!/bin/bash
# Copyright (c) 2015 SHUMEI Inc. All Rights Reserved.
# Authors: Chuanfeng Liu
dirpath=$(cd `dirname $0`;pwd)
#echo $dirpath
export LD_LIBRARY_PATH="$dirpath/ccgo/lib:$LD_LIBRARY_PATH"
#echo $LD_LIBRARY_PATH
if [[ "$1" == "" ]];then
echo "warning: need image path"
fi
./imageHash --image_filename=$1
4:循环执行某二进制文件
#!/bin/bash
for((i=1;i<=8;i++));
do
./hash_test ./相似图片/有缘网相似图片/$i/ ./相似图片/有缘网相似图片/$i/ opencv 7.68
done
5:对文件操作
#!bin/bash
i=1
Folder_A="./opencv_celue_si"
for file_a in ${Folder_A}/*
do
temp_file=`basename $file_a`
echo $temp_file
cat ./opencv_celue_si/$temp_file | awk '{print $4}' > ../aaa.txt
dir="./saveimage/$temp_file/"
if [ ! -d $dir ];then
mkdir "$dir"
fi
cat ../aaa.txt | while read line
do
cp "${line}" ./saveimage/$temp_file/
echo "1111"
done
rm ../aaa.txt
done
6.循环执行bin文件命令
#!/bin/bash
for((i=1;i<=64;i++));
do
./hash_test ./相似图片汇总/相似图片汇总/$i/ ./相似图片汇总/相似图片汇总/$i/ opencv 7.68 #hash_test为二进制文件
done
7.提取两个文件中共同列的值
awk 'NR==FNR{S[$1]=$0;next}NR>FNR{print S[$1],$2,$3}' gpu porn > jiehe
两个具有同一列的文件合并
ps:gpu和porn分别为两个文件名,文件内容分别为:
执行结果为: