Irveen
Irveen

Reputation: 105

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

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 [email protected]
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

Upvotes: 2

Views: 473

Answers (2)

paxdiablo
paxdiablo

Reputation: 882146

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.

Upvotes: 1

igustin
igustin

Reputation: 1118

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?

Upvotes: 0

Related Questions