1

我有几个 .dpff 文件。我想在 Solaris 10 Sparc 中执行以下操作

  1. 收听/等待导演 /cm/vic/digital/orcr/vic_export 到达一个或多个 .dpff 文件。然后
  2. 删除所有 .dpff 文件中的 ^M 字符
  3. 将文件路径添加到所有 .dpff 文件的第一列文件路径为:/cm/vic/digital/orcr/vic_export
  4. .dpff 文件在制表符分隔文件中是当前文件,因此我想将它们转换为管道分隔文件。
  5. 最后,用时间戳重命名每个文件,例如。20140415140648.txt

我的代码如下。我无法达到预期的结果。

请指教。

#! /bin/bash

declare -a files
declare -a z

i=1
z=`ls *.dpff`
c=`ls *.dpff`|wc -l
echo "Start listening for the  .dpff files"
while :;
        do [ -f /cm/vic/digital/orcr/vic_export/*.dpff ]
        sleep 60;

echo " Assing array with list of .dpff files"
for i in c
    do
        dirs[i]=$z
    done

echo " Listing files"

for i in c
    do
        sed   's/^/\/cm\/vic\/digital\/orcr\/\vic_export\//' $files[i] > `date +"%Y%m%d%H%M%S"`.dpfff
        tr '\t' '|' < $files[i] > t.txt

    done
done
4

1 回答 1

3

很难确定你真正问的是什么:你的描述和你的代码并不真正匹配。不过,这是怎么回事?

#! /bin/bash

declare -a files files_with_timestamp

echo "Start listening for the  .dpff files"
while :; do

    # Listen/wait for the director /cm/vic/digital/orcr/vic_export for the
    # arrival of one or more .dpff file 
    while :; do
        files=( /cm/vic/digital/orcr/vic_export/*.dpff )
        (( ${#files[@]} > 0 )) && break
        sleep 60;
    done

    timestamp=$( date "+%Y%m%d%H%M%S" )
    for file in "${files[@]}"; do
        sed -i '
            # Remove the ^M character in all the .dpff files  
            s/\r//g

            # add the file path to the first column of all .dpff files 
            s@^@/cm/vic/digital/orcr/vic_export/@

            # .dpff files are currenlty in tab delimited file so I want to then
            # convert them to the pipe delimited file.
            s/\t/|/g
        ' "$file"
        newfile="${file%.dpff}.$timestamp.dpff"
        mv "$file" "$newfile"
        files_with_timestamp+=( "$newfile" )
    done

    echo ".dpff files converted:"
    printf "%s\n" "${files_with_timestamp[@]}"
done
于 2014-04-15T22:24:00.843 回答