2013-12-14 205 views
1

我正在尝试将数据写入文件。这是剧本。它很容易,也不正确。但是,请帮助我获得输出。将数据写入文件

#!bin/ksh 
DATE=date +'%m/%d/%Y'_$CNTR_SEQ 
file1=$1 # Signifies DATE config file 
file2=$2 # Signifies MONT config file 
file3=$3 # Signifies YEAR config file 
file4=$4 # Signifies SEQN config file 
file5=$5 # Signifies FILETYPE config 
file6=$6 # Signifies CNTR1 config file 
file7=$7 # Signifies CNTR2 config file 


for CNTR_DATE in {0..100}; do 
    for CNTR_SEQ in {1..4}; do 
     NEXT_DATE=$(date +%m-%d-%Y_$CNTR_SEQ -d "$DATE + $CNTR_DATE day") 
     echo $NEXT_DATE 
     if [ -f $5=TST ]; then 
      printf "$3-$2-$1|$4|\n0000000|0\n00000" > echo TST_$NEXT_DATE.dat 
      # This is the content of file.This should be the file creation with 
      # that date's name pattern.The contents of file is been written into 
      # a specific name pattern. Is this correct? 
     fi 
     cat /MYDIR/$echo 
     # A file is creating in the MYDIR /FILE_NAME path. 
     exit(0) 
    done 
done 
+0

请修复格式。它看起来像你的问题文本以某种方式陷入了你的脚本中间。请注意格式化,阅读格式不正确的问题确实非常困难。 – janos

+0

您似乎没有在任何地方设置$ DATE。 –

+0

此外,您没有结束}以匹配“if”语句前面的开头行。 –

回答

0

很难想象你要完成的事情。也许:

#!/bin/ksh 
for days in {0..100}; do 
    future_date=$(date -d "+$days days" +%m-%d-%Y) 
    for seq in {1..4}; do 
     file="/mydir/TST_${future_date}_${seq}.dat" 
     if [ $5 = "TST" ]; then 
      printf "$3-$2-$1|$4|\n0000000|0\n00000" > "$file" 
     fi 
    done 
done 

避免使用所有大写变量名称。有一天,你会使用一个名为PATH的变量,然后想知道为什么你开始看到“command not found”错误。

我完全同意评论“use%Y-%m-%d”