The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Greping columns data from file. esungoe Shell Programming and Scripting 6 08-05-2008 09:11 AM
Adding header to an existing file shash UNIX for Dummies Questions & Answers 5 07-24-2008 08:46 AM
Adding columns to a file figaro UNIX for Dummies Questions & Answers 5 07-21-2008 02:50 AM
Perl: adding columns in CSV file with information in each dolo21taf Shell Programming and Scripting 1 03-05-2008 02:52 AM
Need to add a line of data to already existing file in Unix.. charan81 Shell Programming and Scripting 4 01-21-2006 03:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-09-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433

Code:
nawk -f Test.awk DCDB.xml LDS.xml input > input_new.txt

Jean-Pierre.
  #2 (permalink)  
Old 09-10-2008
Sandeep_Malik Sandeep_Malik is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 27
Not required this time

Last edited by Sandeep_Malik; 10-17-2008 at 03:45 AM..
  #3 (permalink)  
Old 09-11-2008
Sandeep_Malik Sandeep_Malik is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 27
Not required this time

Last edited by Sandeep_Malik; 10-17-2008 at 03:45 AM..
  #4 (permalink)  
Old 09-13-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
I don't understand your requirement.
Please post sample files (DCDB.xml, LDS.xml and inputfile) and required output.


Jean-Pierre.
  #5 (permalink)  
Old 09-14-2008
Sandeep_Malik Sandeep_Malik is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 27
Not required this time

Last edited by Sandeep_Malik; 10-17-2008 at 03:44 AM..
  #6 (permalink)  
Old 09-14-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433

Code:
> rm out.txt
> cat Malik.awk
#
# DCDB - This block select all DCBEntry records
# and memorize Folder and TZ.
# => Folder[dcdb] and Tz[dcdb]
#

/^[[:space:]]*<DCDBEntry / {        # Select DCDBEntry records
   split($0, dcdb, /"/);            #    Split record into dcdb array (sep=")
                                    #      dcdb[2]=dcdb, dcdb[4]=folder,
                                    #      dcdb[6]=tz
   sub(/ *$/, "", dcdb[2]);         #    Remove trailing spaces from dcdb
   Folder[dcdb[2]] = dcdb[4];       #    Memorize folder for dcdb
   next;                            #    Proceed next input record
}                                   #

#
# LDS - This block select all LDSEntry records
# and memorize SiteUnit and Devide for folder,tz
# => SiteUnit[folder,tz] and Devicefolder,tz
#

/^[[:space:]]*<LDSEntry / {         # Select LDSEntry records
   split($0, lds, /[":]/);          #    Split record into lds array (sep=" or sep=:)
                                    #      lds[2]=folder, lds[3]=siteunit
                                    #      lds[4]=device, lds[6]=tz
   folder = lds[2];                 #    Get folder
   ldsv   = lds[6];                 #    Get LDSValue
   SiteUnit[folder, ldsv] = lds[3]; #    Memorize siteunit for folder,LDSValue
     Device[folder, ldsv] = lds[4]; #    Memorize device for folder,LDSValue
   next;                            #    Proceed next input record
}                                   #

#
# Input - These blocks proceed inputfiles
#

/^[[:space:]]*</ || NF==0 {         # Select (and ignore) records from DCDB and LDS and empty records
                                    # (DCDBEntry ans LDSEntry have already been processed)
   next;                            #    Procced next input record
}                                   #

FNR==1 {                            # Select first record of inputfile (logically all other files
                                    # have been processed in previus blocks).
   print $0, "Folder", "SU", "Dev"; #    Print first record (headers) and add new headers
   next;                            #    Proceed next input record
}                                   #

$2 == "TOTAL" {                     # Select TOTAL record
   print;                           #   Print TOTAL record
   next;                            #   Proceed next input record
}

{                                   # Select all reamaining inputfile records
   dcdb_in = $2;                    #    Get dcdb from input record
   if (length(dcdb_in) > 7) {       #    Check if dcdb and LDSValue merged
      ldsv    = substr(dcdb_in,8);  #       extract dcdb
      dcdb_in = substr(dcdb_in,1,7);#       extract LDSValue
   } else                           #    not merged
      ldsv    = $3;                 #    Get LDSValue from input record
   folder = Folder[dcdb_in];        #    Get memorized folder for this dcdb
   su     = SiteUnit[folder, ldsv]; #    Get memorized siteunit for this forder,ldsv
   dev    =   Device[folder, ldsv]; #    Get memorized device for this forder,ldsv
   print $0, (folder ? folder : "?"), (su ? su : "?"), (dev ? dev : "?"); # Print record,
                                    #    folder, siteunit and device (unknown values are
                                    #    replaced by ?
   next;                            #    Proceed next input record
}
> cat Malik.sh
awk -f Malik.awk \
       DCDB.xml  \
       LDS-*.xml \
       LIVE9091.S20080817.txt \
       > out.txt
> Malik.sh
> diff -b out.txt LIVE9091.S20080817_new.txt
>

Jean-Pierre.
  #7 (permalink)  
Old 09-15-2008
Sandeep_Malik Sandeep_Malik is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 27
I really thaks for your awk programming support.
Once again Thanks a lot , Now it is working fine.

Thanks & Regards
Sandeep Malik
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0