zoukankan      html  css  js  c++  java
  • create_txt.sh

    
    #!/bin/bash
    
    # dataset_path="$1"
    dataset_path="/home/aistudio/work/PaddleSeg/dataset/rs_data/"
    #if [ -n str1 ]       当串的长度大于0时为真(串非空) 
    # if [ -z str1 ]      当串的长度为0时为真(空串)  
    
    # debug:
    # if [! -n $dataset_path ]; then
    
    if [ -n $dataset_path ]; then
        cd $dataset_path
        echo "cd dataset_path"
    fi
    # 1.if 条件判断关键字
    # 2.[ ] 语法要求
    # 3.-f 文件比较运算符,如果filename为常规文件,则为真
    # 4.$home 取变量的值
    if [ -f img_train.zip ] && [ -f lab_train.zip ]; then
        if [ -f train_list.txt ]; then
            echo "File train_list.txt has existed."
        elif [ -f val_list.txt ]; then
            echo "File val_list.txt has existed."
        else 
            echo "unzip img_train.zip..."
            # 一、>/dev/null将标准输出重定向到空设备,即我们常说的“黑洞”
            # 二、2>表示错误输出
            # 三、&表示等同的意思
            # 四、1标准输出
            # 五、2>&1就表示错误输出重定向等同于标准输出
            #  > /dev/null 2>&1 就表示
            # 将标准输出及错误输出全部重定向到“黑洞”,这么做可以有效的防止结果输出到控制台,以及inode节点被写满。
            unzip img_train.zip > /dev/null 2>&1
            echo "unzip lab_train.zip..."
            unzip lab_train.zip > /dev/null 2>&1
            # 一、scriptname > filename
            # 重定向scriptname的输出到文件filename中去,如果文件存在则覆盖
            # 二、command > &2 
            # 把command的标准输出(stdout)重定向到标准错误(stderr)中;
            # 三、sort > filename
            # sort命令在进行大文件排序,会自动使用外排序,此时默认会在/tmp目录下新建一个大文件,排序完成后删除。
            find img_train -type f | sort > train.ccf.tmp
            find lab_train -type f | sort > train.lab.ccf.tmp
            # paste -d "#" a b ------>   a#b
            # 注:-d指定分隔符,不加此参数默认为制表符。
            paste -d " " train.ccf.tmp train.lab.ccf.tmp > all.ccf.tmp
            # grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大。
            # 简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理。
            awk '{if (NR % 50 != 0) print $0}' all.ccf.tmp > train_list.txt
            awk '{if (NR % 50 == 0) print $0}' all.ccf.tmp > val_list.txt
        
            rm *.ccf.tmp
            echo "Create train_list.txt and val_list.txt."
        fi
    fi
    
    if [ -f img_testA.zip ]; then
        if [ -f testA_list.txt ]; then
            echo "File testA_list.txt has existed."
        else
            echo "unzip img_testA.zip..."
            unzip img_testA.zip > /dev/null 2>&1
            # find img_testA -type    指定文件的类型,可选的类型包含普通文件f  文件夹文件d  符号文件l  字符设备c  块设备b等.
            find img_testA -type f | sort > testA_list.txt
            echo "Create testA_list.txt."
        fi
    fi
    
    if [ -f img_testB.zip ]; then
        if [ -f testB_list.txt ]; then
            echo "File testB_list.txt has existed."
        else
            echo "unzip img_testB.zip..."
            unzip img_testB.zip > /dev/null 2>&1
            find img_testB -type f | sort > testB_list.txt
            echo "Create testB_list.txt."
        fi
    fi
    
    
  • 相关阅读:
    daper
    存储过程事务
    dengluzhucehaiyouxianshiMVC
    遍历加监听
    类的操作
    轮播图
    定时器的应用(三)
    定时器的应用(二)
    定时器的应用(一)
    延时调用
  • 原文地址:https://www.cnblogs.com/hugeng007/p/13843571.html
Copyright © 2011-2022 走看看