Compare two and write updated output in third file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two and write updated output in third file
# 1  
Old 08-06-2015
Compare two and write updated output in third file

Hi Linux Experts.

I have a requirement where i need to update the thousands of table definitions to extend the column length and character set therefore i am looking for some sort of linux script which i can use to update the length and chacterset.

I have two files

In first file i have 7 below columns.

Code:
DataBaseName,TableName,ColumnName,ColumnLength,ColumnCharacterSet,Ext_ColumnLength,Changed_ColumnCharacterSet

where as in Second file i have ddls of all the tables.

Now first i want to compare the Databasename.TableName from first file with the DatabaseName.TableName in second file if there is a match in second file then update the column parameters i.e., 'ColumnName ColumnLength ColumnCharacterSet' with 'ColumnName Ext_ColumnLength Changed_ColumnCharacterSet'

Sample files and required outout is given below.

Code:
DB_TEST|TABLE_TEST|DEF|100|Latin|270|Unicode
DB_TEST|TABLE_TEST|JKL|100|Latin|270|Unicode

File2

Code:
    CREATE MULTISET TABLE DB_TEST.TABLE_TEST ,NO FALLBACK ,
         NO BEFORE JOURNAL,``
         NO AFTER JOURNAL,
         CHECKSUM = DEFAULT,
         DEFAULT MERGEBLOCKRATIO
         (
          ABC VARCHAR(200) CHARACTER SET LATIN NOT CASESPECIFIC,
          DEF VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
          GHI VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
          JKL VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
          )
    INDEX ( ABC ) ;

Required OutPut

Code:
    CREATE MULTISET TABLE DB_TEST.TABLE_TEST ,NO FALLBACK ,
         NO BEFORE JOURNAL,``
         NO AFTER JOURNAL,
         CHECKSUM = DEFAULT,
         DEFAULT MERGEBLOCKRATIO
         (
          ABC VARCHAR(200) CHARACTER SET LATIN NOT CASESPECIFIC,
          DEF VARCHAR(240) CHARACTER SET UNICODE NOT CASESPECIFIC,
          GHI VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
          JKL VARCHAR(240) CHARACTER SET UNICODE NOT CASESPECIFIC,
          )
    INDEX ( ABC ) ;

Thanks for your help.

Moderator's Comments:
Mod Comment Do not put you entire post in HTML tags, instead use CODE tags for code and data samples, but leave the rest of your text as is

Last edited by Scrutinizer; 08-07-2015 at 02:35 AM.. Reason: Removed HTML text, added specific CODE tags
# 2  
Old 08-07-2015
Hi, try:
Code:
awk '
  NR==FNR{
    $0=toupper($0)
      A[$1"."$2,$3,$4]=$6
      A[$1"."$2,$3,$5]=$7
      next
    }
    $1=="CREATE"{
      t=$4
    }
    $2~/VARCHAR/ {
      split($2,F,/[()]/)
      if ((t,$1,F[2]) in A)
        sub(F[2],A[t,$1,F[2]])
      if ((t,$1,$5) in A)
        sub($5, A[t,$1,$5])
  }
  1
' FS=\| file1 FS=" " file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare two files and write data to second file using awk

Hi Guys, I wanted to compare a delimited file and positional file, for a particular key files and if it matches then append the positional file with some data. Example: Delimited File -------------- Byer;Amy;NONE1;A5218257;E5218257 Byer;Amy;NONE1;A5218260;E5218260 Positional File... (3 Replies)
Discussion started by: Ajay Venkatesan
3 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

Compare 2 file and write result

Hi friends...I have 2 files, file1.txt and reference.txt I could able to find difference using diff and following command awk 'NR == FNR { A=1; next } !A' reference.txt file1.txt above command listing data which is not in reference.txt 12.12 87 11.95 88 11.83 89 12.55 84... (12 Replies)
Discussion started by: Akshay Hegde
12 Replies

5. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

6. Red Hat

write execl output to file

hi, how to write the resullt of execl() into another file. i used write(fd,execl()); (1 Reply)
Discussion started by: Mahendravarma
1 Replies

7. Shell Programming and Scripting

output to write in a file

hi all, when i try to start an applicationserver for an example: ./kStart.sh > out.txt so kStart.sh script will start the application server and write the details to out.txt but in mycase... it is writing to out.txt and as well it is showing in the prompt also... I want only the... (2 Replies)
Discussion started by: raghur77
2 Replies

8. Shell Programming and Scripting

Write process output to a file

When I run <ls -l> to get a list of all the files, I want the displayed result to be written to a text file. Is there a way to do that? (1 Reply)
Discussion started by: kn.naresh
1 Replies

9. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

10. Shell Programming and Scripting

How can i extarct the output from a file which has been updated from last half an hou

hi, I have a log file , which is appending with current data i need the extarct which is updated from last 30 minutes the format of the date is Jun 18, 2008 8:59:18 AM how can i subtract 30 mins from the current date thanks Tarun. (5 Replies)
Discussion started by: tarundeepdhawan
5 Replies
Login or Register to Ask a Question