need to create a shell script or a command in unix which can do the following process(command will be preferred)

风流意气都作罢 提交于 2019-12-20 03:43:22

问题


at the following path

\\ncsusnasent02.na.jnj.com\its_diq_na_win_dev\PowerCenter\infa_shared\WCPIT_BIO_EDW\SrcFiles\DDDMD\DDD.CLI026.WK0933.DDDMR45.001.head

I have one file DDD.CLI026.WK0933.DDDMR45.001.head

if i open this file i get data as following(in a single line)

HEADER0101IMS HEALTHDMD Weekly D DD.CLI026.WK0933.DDDMR45 Centocor DMDDRM45 W2009080210120090831125325ssnyder@us.imshealth.com
TRAIL0101 000000000581 0000000000CKSUM000002236804730

we need to copy 581(it will not be same always it gets updated everyday) from this file and update it at following location

\\ncsusnasent02.na.jnj.com\its_diq_na_win_dev\PowerCenter\infa_shared\WCPIT_BIO_EDW\PrmFiles\LND\IMS_FILE_to_LND.par

when i open this file it has data as following

[WCPIT_BIO_EDW.WF:w_DDDMD_LNDG_IMS_NONRET_SALES]
$$Cust_RowCount=72648
$$Sales_RowCount=5235998
$$OuletChangeLog_RowCount=931
**$$DRM45_RowCount=581**
$$Control_RowCount=4495
$$Outl_Subcat_RowCount=105
$$Fac_Subcat_RowCount=149

we need to update 581 against $$DRM45_RowCount


回答1:


Assuming that header is all on a single line (and the "**" are added by you just to emphasize what you want extracted), you can extract the number with:

export num=$(expr 0 + $(cat infile | cut -c137-148))

This extracts the number (assuming your file is specified correctly). The expression "0 + n" will strip off leading zeros. Then, using my code from your other question:

cat parfile | awk -va=${num} '{
    if (substr($0,1,17) == "$$DRM45_RowCount=") {
        print "$$DRM45_RowCount=" a
    } else {
        print
    }
}' > newparfile

Now newparfile should contain the value you want.




回答2:


Probably you can solve this using Windows scripting (I'm not expert in that), but usually I rather install CygWin and wrote a bash/awk/sed script for such operations. Is this acceptable for you and your situation?



来源:https://stackoverflow.com/questions/1409565/need-to-create-a-shell-script-or-a-command-in-unix-which-can-do-the-following-pr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!