我有几个.dpff文件。我想在Solaris 10 Sparc中执行以下操作
我的代码如下。我无法达到预期的效果。
请建议。
#! /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
答案 0 :(得分: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