小编vik*_*ana的帖子

根据某种模式选择和移动独特的文件

我在 Linux 机器上有一个文件列表,这些文件在某个日期上有所不同,所以我必须搜索唯一的文件并需要将它们放在其他目录中。“唯一”在这里指的是文件,直到第二的名字_,所以100001_ABC并100001_XYZ在下面的例子。

100001_ABC_25Sep2020_1200-25Sep2020_1300.csv  
100001_XYZ_30Sep2020_1300-30Sep2020_1400.csv  
100001_XYZ_30Sep2020_1400-30Sep2020_1500.csv
Run Code Online (Sandbox Code Playgroud)

我希望将唯一命名的放在此目录下:

/home/vikrant_singh_rana/uniquefiles/
Run Code Online (Sandbox Code Playgroud)

该脚本应仅复制以下文件:

100001_ABC_25Sep2020_1200-25Sep2020_1300.csv  
100001_XYZ_30Sep2020_1300-30Sep2020_1400.csv  
Run Code Online (Sandbox Code Playgroud)

这是我的 shell 脚本

#!/bin/bash
set +o posix
#reading file names into file_array
readarray -t file_array < <(
    cd "/home/vikrant_singh_rana/unzipfiles"
    printf "%s\n" * | cut -d"_" -f2 | cut -d"-" -f1 | sort -u )

#print items of array
printf '%s\n' "${file_array[@]}"


for i in "${file_array[@]}"; do
        #echo $i
        find /home/vikrant_singh_rana/unzipfiles/ -type f -name "*$i*.csv" -exec awk '!seen[$0]++' {} +
done
Run Code Online (Sandbox Code Playgroud)

该脚本可以正确找到唯一名称,但我找不到如何将它们移动到另一个目录。

shell-script rename mv

2
推荐指数
1
解决办法
359
查看次数

在 shell 中嵌套 if else 语句

我无法理解下面的 if else 语句出了什么问题。

if [ "$technology" == "AN_EUD" ] then
        if [ "$temporal_unit" == "15min" ] && [ "$regional_unit" == "node" ]
        then
                parm="DEVICEID"
        elif [ "$temporal_unit" == "15min" ] && [ "$regional_unit" == "trunk" ]
        then
                parm="DEVICEID"
        else echo "Unkown parameter"
        fi
else [ "$technology" == "IP" ] then
        if [ "$temporal_unit" == "15min" ] && [ "$regional_unit" == "item" ]
        then
                parm="ME_NAME"
        elif [ "$temporal_unit" == "min" ] && [ "$regional_unit" == "item" ]
        then
                parm="DEST"
        else …
Run Code Online (Sandbox Code Playgroud)

shell-script

0
推荐指数
1
解决办法
62
查看次数

标签 统计

shell-script ×2

mv ×1

rename ×1