Strange Logic

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Strange Logic

Post by kashif007 »

I am trying to read a file and skip few records based upon the following two columns. Pipe delimiter used between the two columns.
Column1|Column2
Property|CutOff
Target|11111
Min|9999
Max|10000
Comment|This is a test
Property|Weight
Target|222
Min|3434
Max|77777
UOM|mm
Comment|This is a test
Property|Temperature
Target|
Min|
Max|
UOM|
Property|Adhesive
Target|4
Min|3
Max|6
UOM|inch

Whenever I find a word "property" in column1, I have to check if column2 contains data in it till the next property word arrives in column1. If column2 does not contain any data for some property in column1 (like in case of the property called Temperature) then I have to skip that Property data and use the next Property data(which is adhesive). Can any one tell me how can I accomplish this challenging logic. I will appreciate any help.
Thanks
Regards
Kashif Khan
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Run in sequential mode and filter out all records that are empty in the second column. This will leave you with all records that have data in the second column including two or more adjacent rows with Property in the first column. Pass it through the transformer see if you have adjacent rows with same values in column 1. Skip all, except last.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Sreedhar
Participant
Posts: 187
Joined: Mon Oct 30, 2006 12:16 am

Post by Sreedhar »

Just write a small script to do so.....


awk -F"|" '$1/Property/ {print $1, $2}' File_Name > OutputFilename

Should help you...

do let me know if you have any prob.....with this...
Regards,
Shree
785-816-0728
ganesh123
Participant
Posts: 70
Joined: Tue Feb 20, 2007 3:22 pm
Location: NJ,USA
Contact:

Post by ganesh123 »

Write a shell script

Code: Select all

awk -F"|" ' /Property/ { tmp=$0 ; getline; if($2 != "" ) print tmp } $2 != ""
 ' file
Or as DSGuru suggested do it in TX use contraint

Code: Select all

 NOT(ISNull(read.column1)) 
[/code]
If women didn't exist, all the money in the world would have no meaning.
-- Aristotle Onassis
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

Both Sreedhar and Ganesh's code have produced same output
I am using this code

awk -F"|" ' /Property/ { tmp=$0 ; getline; if($2 != "" ) print tmp } $2 != "" ' Test5 > Test6

Correct me if I am wrong
Regards
Kashif Khan
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Use that code as a filter command in your sequential file stage. You do not need to redirect the output to a file.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

I used the same code to filter in the sequential file stage and I see still the data exhisting when I read the file. The UNIX code has something missing it in to Filter out according to my requirement.

awk -F"|" ' /Property/ { tmp=$0 ; getline; if($2 != "" ) print tmp } $2 != "" '
Regards
Kashif Khan
ganesh123
Participant
Posts: 70
Joined: Tue Feb 20, 2007 3:22 pm
Location: NJ,USA
Contact:

Post by ganesh123 »

Have you tried the command from command prompt ??
Let me know if it gives desired result...
If women didn't exist, all the money in the world would have no meaning.
-- Aristotle Onassis
ganesh123
Participant
Posts: 70
Joined: Tue Feb 20, 2007 3:22 pm
Location: NJ,USA
Contact:

Post by ganesh123 »

By the way how you filter in Seq file itself ?? :roll:

Sorry I am a Rookie in PX...
If women didn't exist, all the money in the world would have no meaning.
-- Aristotle Onassis
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

I tried doing it on a putty and then as DSguru said typed the same logic in the Filter option for Sequential file and I get my exact file as out put.

Goto Options and use "Filter" and then type the UNIX code in there to get the data. When I read the data I dont see any change in the data as I have desired.
Regards
Kashif Khan
ganesh123
Participant
Posts: 70
Joined: Tue Feb 20, 2007 3:22 pm
Location: NJ,USA
Contact:

Post by ganesh123 »

Ok but what you get if you run in putty ?

Do you see the changes ??

Redirect it to another file to check if its correct ...
If women didn't exist, all the money in the world would have no meaning.
-- Aristotle Onassis
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

Thats what I mean there are no changes to the file. Here is the code that I am using in Putty.

awk -F"|" ' /Property/ { tmp=$0 ; getline; if($2 != "" ) print tmp } $2 != "" ' Test5 > Test6

When I see Test6 file its exactly the same as Test5. No changes to the file. Infact I should have had four rows dropped out of my input data.
Regards
Kashif Khan
ganesh123
Participant
Posts: 70
Joined: Tue Feb 20, 2007 3:22 pm
Location: NJ,USA
Contact:

Post by ganesh123 »

I have sent you a PM check it out and respond.

Try this in Shell script

and run it-

Code: Select all

#Shell Script name  ganesh.awk 
BEGIN {
  FS=OFS="|"
}

tolower($1) == "property" { _prop=$0 ; skip=0;next}
$2 == "" {skip++;next}
!skip { print _prop; skip++;next }
1
Run it using -

Code: Select all

nawk -f ganesh.awk myFile.txt
If women didn't exist, all the money in the world would have no meaning.
-- Aristotle Onassis
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

ganesh, your command works fine on command line, I tested it out too. The first awk command that you posted.
kashif, why does'nt the command work as a filter for you? Try it out on command line as others requested. Also make sure that the columns that are supposed to be empty are "really empty" and not have a space in it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

It works my friends.
Thank you so much actually I had space in the Data.
So that brings another question in my mind. Actually if I have space in the column and if I had to drop those then what do I do.

Thanks for your help guys. You guys are the best.
Regards
Kashif Khan
Post Reply