开发者

process text file in ksh append data

Following doesn't work. I need to add a , and an input param at the end of the script. Please help

#!/bin/ksh

data_log="/usr/data/data_log.dbg"
err_file=开发者_如何学JAVA"/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}


Replace the for logger in loop where you're reading the file with this:

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

...which I think can be written like this (no shell to test with at the moment) to avoid a UUOC...

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜