【问题标题】:process text file in ksh append data在 ksh 中处理文本文件附加数据
【发布时间】:2010-12-02 16:52:21
【问题描述】:

以下不起作用。 我需要在脚本末尾添加一个 , 和一个输入参数。请帮忙

#!/bin/ksh

data_log="/usr/data/data_log.dbg"
err_file="/usr/data/data_log.err"

if [ $# -eq 1 ]; then
    inParam=$1
fi

processInfo ${inParam} > ${data_log}

#Append ,inParam to each line in log for further processing
for logger in `cat ${data_log}`
{
    echo ${logger} | sed s/$/,${inParam}/ >> ${err_file}
}

rm -rf ${data_log}

【问题讨论】:

    标签: regex sed ksh


    【解决方案1】:

    用这个替换你正在读取文件的for logger in循环:

    cat ${data_log} | while read line
    do
        echo "${line},${inParam}" >> ${err_file}
    done
    

    ...我认为可以这样写(目前没有要测试的外壳)avoid a UUOC...

    while read line
    do
        echo "${line},${inParam}" >> ${err_file}
    done < ${data_log}
    

    【讨论】:

      猜你喜欢
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-21
      • 2015-02-04
      • 1970-01-01
      • 2018-08-23
      相关资源
      最近更新 更多