Need Help for Adding Three new columns in existing file from fatching data from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help for Adding Three new columns in existing file from fatching data from file
# 1  
Old 08-25-2008
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 03:53 AM..
# 2  
Old 08-25-2008
Please, give us examples of input and output files.

Jean-Pierre.
# 3  
Old 08-25-2008
Not required this time

Last edited by Sandeep_Malik; 10-17-2008 at 03:33 AM.. Reason: Not required this time
# 4  
Old 08-25-2008
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  
Old 08-26-2008
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  
Old 08-26-2008
Try nawk or gawk instead of awk.

Jean-Pierre.
# 7  
Old 08-26-2008
Thanks Jean for prompt reply
I'll try with nawk and share my experiance with you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with add existing file name as new data column in new output file

Input File 1 cat S1.txt MI0043 2731 miR-1 Input File 2 cat S4.txt MI006 310 CiR-1 MI057 10 CiR-24 MI750 5 CiR-24 Desired Output File 1 cat S1.txt.out MI0043 2731 miR-1 S1.txt Desired Output File 2 cat S4.txt.out MI006 310 CiR-1 S4.txt (3 Replies)
Discussion started by: perl_beginner
3 Replies

2. Shell Programming and Scripting

Adding columns with values dependent on existing columns

Hello I have a file as below chr1 start ref alt code1 code2 chr1 18884 C CAAAA 2 0 chr1 135419 TATACA T 2 0 chr1 332045 T TTG 0 2 chr1 453838 T TAC 2 0 chr1 567652 T TG 1 0 chr1 602541 ... (2 Replies)
Discussion started by: plumb_r
2 Replies

3. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

4. Shell Programming and Scripting

Awk to add columns from a file into an existing file

Hi! I would need some help to add the last two columns of one file into another file using awk (or something similar). For example, I have: file 1: file 2: car book day root lag bar look pay boot tag tar took may moot sag I want to have:... (5 Replies)
Discussion started by: coconaza
5 Replies

5. Shell Programming and Scripting

add more data to existing data in a file

Hi all, I need help to add additional data from file2 to existing data in file 1 using awk, sed or perl. the ID in file 1 should match against field $3 in file2 file1 #this is a new game ID HR_1 BASE1 30 BASE2 37 DETAIL No TYPE L @@ ID HR_10 BASE1 6030 BASE2 ... (4 Replies)
Discussion started by: redse171
4 Replies

6. Shell Programming and Scripting

Adding existing set of records in the same file

I have a file with 50,000 records in it, i have a requirement to use the same 50,000 records and add them 4 times to the same file to make a total of 200,000 records. I was wondering how to do this using ksh. Any help is greatly appreciated. (2 Replies)
Discussion started by: vpv0002
2 Replies

7. Shell Programming and Scripting

Adding a new column in a file with other existing columns

Hi All , Kindly help me with this soln awk '{printf "%s %7s \n", $1,$c}' infile where value of variable c I am externally giving input But executing the above command shows all the columns of infile where as I want only 1st column of infile and 2nd column should print value c (8 Replies)
Discussion started by: Pratik4891
8 Replies

8. Shell Programming and Scripting

Adding file to an existing tar

Hi Friends, I want to know the command to add a new file in a existing tar file. For Ex: I have a tar file file1.tar with the contents one.txt two.txt three.txt Now I need to add file four.txt to this existing tar file, how can I do it? Thanks in advance (4 Replies)
Discussion started by: mr_manii
4 Replies

9. UNIX for Dummies Questions & Answers

Add line with data to existing file

i have a file called motors with 3 columns separated with tabs eg: car make reg i want to create a executable file that will add a line with data eg: car make reg benz s600 t35778 can you please show me how to do this? (7 Replies)
Discussion started by: fletcher
7 Replies

10. UNIX for Dummies Questions & Answers

Adding header to an existing file

Dear All, I need to add a header of one line to an already existing file. I know that it can be achieved by the following: echo "Header" > newfile cat file1 >> newfile But my problem is that file is huge and there is no space for creating a new file every time. Is there a way that I can... (5 Replies)
Discussion started by: shash
5 Replies
Login or Register to Ask a Question