Need Logic in creation of shell script

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Need Logic in creation of shell script

Post by khanparwaz »

Hi ,
I need to create a shell script to perform a validation on a file, ihave a file which is ~ seperated.The File contents Looks like below:


HEADER~NFOS-LOH~CIGMA~20051109~124430~ 63893
TRADE_ACTION~TRADE_TYPE~CONTRACT_ID~TRADE_DATE~LOCAL_PRODUCT_TIERA~LOCAL_PRODUCT_TIERB~LOCAL_PRODUCT_TIERC~PUBLISH_DATE_TIME~SOURCE_SYSTEM~ORIGINATING_SYSTEM~SITE_CODE~ENTERED_USER_ID~TRADING_ACRONYM~TRADING_ACRONYM_ISD~TRADING_ACRONYM_TREATS~TRADING_ACRONYM_DESCRIPTION~PRICE~PRIMARY_CURRENCY~PRIMARY_AMOUNT~PRIMARY_SETTLE_DATE~SECONDARY_CURRENCY~SECONDARY_AMOUNT~SECONDARY_SETTLE_DATE~TRADE_STATUS~LAST_MODIFIED_DATE~TRADE_ID~GLOBAL_TRADE_ID~BOOK~BOOK_ENTITY~INTERNAL_BOOK~PREVIOUS_TRADE_ID~ALTERNATE_TRADE_ID~LINKED_TRADE_ID~EVENT_CLASS~TRADE_TYPE_FACTOR~VALUE_ADDED_AMOUNT~VALUE_ADDED_CCY~TRADE_CHANNEL~SALESPERSON_ID~BROKER~INSTRUMENT~BUY_SELL_INDICATOR~VALUE_ADDED_AMOUNT_LOCAL~VALUE_ADDED_CURRENCY_LOCAL~SALES_MARGIN_ON_RATE~WHOLESALE_RATE~CURRENCY_QUOTATIONNEW~~231750~20041013~Spot-Forward~FXFORWARD~FWD~20050610T10:51:01~NFOS~FXALL LOH~LOH~CONVERT~H.TUB GCOREAG~77051~TRING8C~HSBC TUB-GLENCORE AG~1.22966500~USD~99157.11143750~20060203~EUR~80637.50000000~20060203~LIVE~00000000~238445~0003XWD042870213~FWD_EUR_LDN~H.PLC LDN~~0~532092LOH678/2.1.5341879-5-0//~0~~~0.00~USD~FXALL~~~EUR/USD~B~5~GBP~0.0000~1.229665000~USD/EURTRAILER~NFOS-LOH~CIGMA


row in red, header row standard number of ~ would be 5
row in green, column name row standard number of ~ would be 46
row in blue, actual data row standard number of ~ would be 46

The logic i am putting is like standard=count of rows*46-85
actual=count of occurence of each ~ in File

shell script would be like
if
standard = actual then
1
else
0
fi

i am unable to work around with grep & wc command which also includes some calculation as u can see in calculation of standard.


Pls help me out
Thanks in advance
Pls do let me know if you need any more clarification
i am looking for a shell script to solve this particular problem.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Can you not use a DataStage job with one transform using stage variables in order to solve this problem? A short perl or awk would do it as well, but since you have DS you might as well use it.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi,
As Arnd suggested you can use datastage Basic code to accomplish this.
You can use wc to fram a loop.
You can use "Count()" function to count the number of "~" present in the file.
Then you can reconcile.

-Kumar
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post by khanparwaz »

Ok fine jest tell me how can i count occurence of each ~ in a file through datastage jobs rest i will try from my own.

if u say i have to use the routine

i have already treid commang grep -c '~' filename

but its not giving me satisfactory results
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Read each record in as a single large varchar. Use the 'count' function to see how many '~' characters are in each record. Use either @INROWNUM or the 'field' command to peel off the first value in each row to know which record type you are processing and how many tildes it should have.
-craig

"You can never have too many knives" -- Logan Nine Fingers
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post by khanparwaz »

Thanks For all help
i am done with this process its working fine now i am able to calculate my number of tilde in my file & also able to do validation for file.

It was really a great help from dsxchange menbers.
Post Reply