Strange Logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange Logic
# 1  
Old 03-20-2007
Strange Logic

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
# 2  
Old 03-20-2007
Code:
awk -F "|" {if ($1 != "" && $2 != "") {print $0} else {next} };
END

Plz help if its wrong... Thanks

Last edited by ganesh123; 03-20-2007 at 12:37 PM..
# 3  
Old 03-20-2007
nawk -f ganesh.awk myFile.txt

ganesh.awk:
Code:
BEGIN {
  FS=OFS="|"
}

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


Last edited by vgersh99; 03-20-2007 at 01:48 PM..
# 4  
Old 03-20-2007
Code:
awk -F"|" ' /Property/ { tmp=$0 ; getline; if($2 != "" ) print tmp } $2 != ""
 ' file

# 5  
Old 03-20-2007
Thank you guys.
# 6  
Old 03-20-2007
Thanks once again

Last edited by ganesh123; 03-20-2007 at 06:16 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with logic

I am on solaris and i have this piece of code. echo "SQLPLUS CONNECTION" sqlplus -s $ARBOR_USR/$ARBOR_DB_PASSWD@$ORACLE_SID<<EOF>$CUR_DIR/sql_output.txt set feedback off set heading off select distinct account_no from adj WHERE ADJ_TRANS_CODE=-2401 and request_status=1 and bill_ref_no=0... (1 Reply)
Discussion started by: rafa_fed2
1 Replies
Login or Register to Ask a Question