The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 08:11 AM
Adding header to an existing file shash UNIX for Dummies Questions & Answers 5 07-24-2008 07:46 AM
Adding columns to a file figaro UNIX for Dummies Questions & Answers 5 07-21-2008 01: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
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-25-2008
Sandeep_Malik Sandeep_Malik is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 27
Need Help for Adding Three new columns in existing file from fatching data from file

not required this time

Last edited by Sandeep_Malik; 10-17-2008 at 02:53 AM..
  #2 (permalink)  
Old 08-25-2008
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,358
Please, give us examples of input and output files.

Jean-Pierre.
  #3 (permalink)  
Old 08-25-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 02:33 AM.. Reason: Not required this time
  #4 (permalink)  
Old 08-25-2008
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,358
A possible solution (try and adapt) :
Code:
awk '

#
# DCDB
#

/^<DCDBEntry / {
   split($0, dcdb, /"/);
   sub(/ *$/, "", dcdb[2]);
   Folder[dcdb[2]] = dcdb[4];
       Tz[dcdb[2]] = dcdb[6];
   next;
}

#
# LDS
#

/^<LDSEntry / {
   split($0, lds, /[":]/);
   folder = lds[2];
   tz     = lds[6];
   SiteUnit[folder, tz] = lds[3];
     Device[folder, tz] = lds[4];
   next;
}

#
# Input
#

/^</ {
   next;
}

FNR==1 {
   print $0, "Folder", "SU", "Dev";
   next;
}

{
   dcdb_in = $2;
   folder = Folder[dcdb_in];
   tz     =     Tz[dcdb_in];
   su     = SiteUnit[folder, tz];
   dev    =   Device[folder, tz];
   print $0, (folder ? folder : "?"), (su ? su : "?"), (dev ? dev : "?");
   next;
}

' DCDB.xml LDS-*.xml inputfile
DCDB.xml
Code:
> cat DCDB.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DCDBTable>
<DCDBEntry DCDB="0862976 " folder="768678" timeZone="2"/>
<DCDBEntry DCDB="0911297 " folder="975426" timeZone="1"/>
<DCDBEntry DCDB="0201347 " folder="1389781" timeZone="2"/>
<DCDBEntry DCDB="0800659 " folder="2035595" timeZone="4"/>
<DCDBEntry DCDB="0123033 " folder="2143699" timeZone="2"/>
<DCDBEntry DCDB="0911515 " folder="2315643" timeZone="1"/>
<DCDBEntry DCDB="0123913 " folder="2367867" timeZone="2"/>
<DCDBEntry DCDB="0713934 " folder="2407712" timeZone="5"/>
</DCDBTable>
LDS-*.xml
Code:
> cat LDS-*.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LDSMappingTable>
<LDSEntry LDSKey="3351216:1:TV" LDSValue="7"/>
<LDSEntry LDSKey="1389781:1:VCR1" LDSValue="2"/>
<LDSEntry LDSKey="3351216:2:TV" LDSValue="2"/>
<LDSEntry LDSKey="3351216:3:TV" LDSValue="6"/>
<LDSEntry LDSKey="3351511:1:TV" LDSValue="10"/>
<LDSEntry LDSKey="3351511:1:VCR1" LDSValue="11"/>
<LDSEntry LDSKey="3351511:2:TV" LDSValue="4"/>
<LDSEntry LDSKey="3351511:2:VCR1" LDSValue="5"/>
</LDSMappingTable>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LDSMappingTable>
<LDSEntry LDSKey="3351217:1:XTV" LDSValue="7"/>
<LDSEntry LDSKey="1389782:1:XVCR1" LDSValue="2"/>
<LDSEntry LDSKey="3351217:2:XTV" LDSValue="2"/>
<LDSEntry LDSKey="3351217:3:XTV" LDSValue="6"/>
<LDSEntry LDSKey="3351512:1:XTV" LDSValue="10"/>
<LDSEntry LDSKey="3351512:1:XVCR1" LDSValue="11"/>
<LDSEntry LDSKey="3351512:2:XTV" LDSValue="4"/>
<LDSEntry LDSKey="3351512:2:XVCR1" LDSValue="5"/>
</LDSMappingTable>
Inputfile
Code:
> cat inputfile
1DATE HHIDLDS BothOff 91 NG A=D 90faulRoundOnOff OffOn OthersMATCHED NOMATCH MATCH%
0721 0201136 1 544 . . . 1 . . . 895 1 99.89
0721 0201347 1 1296 . . . . . . . 144 . 100.0
0721 0201347 2 818 . . . . . . . 622 . 100.0
0721 0201364 1 1123 . . . . . . . 317 . 100.0
0721 0201364 2 1327 . . . . . . . 113 . 100.0
Output
Code:
1DATE HHIDLDS BothOff 91 NG A=D 90faulRoundOnOff OffOn OthersMATCHED NOMATCH MATCH% Folder SU Dev
0721 0201136 1 544 . . . 1 . . . 895 1 99.89 ? ? ?
0721 0201347 1 1296 . . . . . . . 144 . 100.0 1389781 1 VCR1
0721 0201347 2 818 . . . . . . . 622 . 100.0 1389781 1 VCR1
0721 0201364 1 1123 . . . . . . . 317 . 100.0 ? ? ?
0721 0201364 2 1327 . . . . . . . 113 . 100.0 ? ? ?
Jean-Pierre.
  #5 (permalink)  
Old 08-26-2008
Sandeep_Malik Sandeep_Malik is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 27
Thanks a lot Jean-Pierre
but still i have facing some error syntax like as:
awk: syntax error near line 1
awk: bailing out near line 1
awk: newline in string near line 8
awk: newline in string near line 20

Please help me
  #6 (permalink)  
Old 08-26-2008
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,358
Try nawk or gawk instead of awk.

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

Join Date: Aug 2008
Posts: 27
Thanks Jean for prompt reply
I'll try with nawk and share my experiance with you
Sponsored Links
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 12:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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