Compare and merging the differences in text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Compare and merging the differences in text file
# 22  
Old 11-10-2011
Thanks vgersh
its printing the start and end tag only once but somehow the file1 pointer is increasing and making the file2 contents changed

please see the differences comparing (file1 ,file2 ) and ( file1 , output )


file1 : is the exact changes what should reflect in output
file2 : file2 changes are redirected to output
please see the attachments

Last edited by rakeshkumar; 11-10-2011 at 03:24 PM..
# 23  
Old 11-10-2011
compare the file contents starting at file1's line:
Code:
007100 01  BRTB-COMM-BYTE-POINTER9 REDEFINES

you have extra blank lines. plus lines containing 007200 are not the same. The code behaves as expected.
This User Gave Thanks to vgersh99 For This Post:
# 24  
Old 11-10-2011
thanks vgersh

i will make sure to format all input files well ,

its great help from your side from past two days , thanks alot!!

---------- Post updated at 03:40 PM ---------- Previous update was at 02:25 PM ----------

Hi Vgersh

To handle such cases i wrote few lines

before doing this i have increased my terminal columns, default was 157 columns
Code:
sdiff -W -w 168 -l file1 file2 > output_sdiff_file1
colrm 82 < output_sdiff_file1 > output_colrm_file1

sdiff -W -w 168 -l file2 file1 > output_sdiff_file2
colrm 82 < output_sdiff_file2 > output_colrm_file2
  

Now i will supply output_colrm_file1_mod and output_colrm_file2 to your awk script which was working superb earlier
# 25  
Old 11-10-2011
Quote:
Originally Posted by rakeshkumar
thanks vgersh

i will make sure to format all input files well ,

its great help from your side from past two days , thanks alot!!

---------- Post updated at 03:40 PM ---------- Previous update was at 02:25 PM ----------

Hi Vgersh

To handle such cases i wrote few lines

before doing this i have increased my terminal columns, default was 157 columns
Code:
sdiff -W -w 168 -l file1 file2 > output_sdiff_file1
colrm 82 < output_sdiff_file1 > output_colrm_file1

sdiff -W -w 168 -l file2 file1 > output_sdiff_file2
colrm 82 < output_sdiff_file2 > output_colrm_file2
  

Now i will supply output_colrm_file1_mod and output_colrm_file2 to your awk script which was working superb earlier
I'm not sure what this will accomplish as you have blank lines AND some of the lines ARE different - see my previous explanation of the findings.
This User Gave Thanks to vgersh99 For This Post:
# 26  
Old 11-11-2011
Hi Vgersh

Actually the input files are not correctly formatted , to format my files i have done below steps

1) my input files(file1,file2) has <=80 columns

so i increased my default columns in putty terminal to 180 by reducing the font and increasing system resolution since set COLUMNS was not working


2) since sdiff was working good for checking the differences and its formatting the data in input files to ignore spaces..etc
Code:
 
i have code all the below steps in format.sh

sdiff -W -w 168 -l file1 file2 > sdiff_file1 
-w : setting columns
-W: eliminated white spaces
168 is the total colums( 84-file2,84-file1),it can be 160 but i used extra columns for readability 

here am redirecting the formatted left side (file1) to sdiff_file1

sdiff -W -w 168 -l file2 file1 > sdiff_file2

similarly i swapped the files and got the (file2) to sdiff_file2

i have checked the output of both files , it contains "(" character at column 83

To cut the character at 83 , i used colrm
Code:
colrm 82 < sdiff_file1 > colrm_file1
colrm 82 < sdiff_file2 > colrm_file2

then to eliminate ^M ,
Code:
tr -d '\015' < colrm_file1 > Tr_file1
tr -d '\015' < colrm_file2 > Tr_file2

finally after this steps i got the formatted text in Tr_file1 and Tr_file2

Now i sent the Tr_file1 and Tr_file2 to awk script you gave and it worked perfectly !!! Smilie

Question : please suggest me any better ways than my above steps for formatting files ( bulk files)

Code:
awk-script.sh Tr_file2 Tr_file1 > output_file2

since i want to retrofit the changes in file2 only

The only Issue:

The output_file2 contains 82 Columns fixed ( because we used cut 82) but the actual file1 ( without formatted ) does not contain any spaces

for example:
line1 code is for 10 columns in file1 ( not formatted one), its fixed to 10 but in output_file2 its 82

is there anyway to reduces the spaces of code in output_file2 to restrict to show only the columns it used not 82 for using 10 character (columns ).

thanks alot ... learned lot of things
# 27  
Old 11-11-2011
I don't quite understand why you need to all these steps, but that's beyond the point - you probably know better.
You can streamline all of these like so, e.g.:
Code:

sdiff -W -w 168 -l file1 file2 | colrm 82 | tr -d '\015' > Tr_file1

The same to be done for the other file.

For the 'The only issue' part.... I don't quite follow what you're after. Can you provide a snippet of a file BEFORE and AFTER - just a small snippet to illustrate the dilemma.
# 28  
Old 11-13-2011
thanks vgersh

Now after generation of output from awk script , i am reviewing by comparing output file with original file, please consider the below scenario difference my external stupid GUI tools is reporting ,column lengths differ
Code:
actual file1 :  columns refer to number of characters in a line
Note: actual file1 is the original file1 as it is without formatting
000001*                                                                 <7 columns>
000002  This is line1 and file1 is the actual file.  <52 columns>
000003  this is line2                                              <22 columns>
000004  this is line3 end of the file1                     <39 columns>

Code:
output file ( generated from awk script )
000001*                                                                 <82 columns>
000002  This is line1 and file1 is the actual file.  <82 columns>
000003  this is line2                                              <82 columns>
000004  this is line3 end of the file1         <82columns>

all the lines are showing as 82 columns size , its shows as difference as length of columns does not match when i am comparing the both files
i want the output file to contain exactly the columns it occupies in original file

i have tried some tricks to delete the extra spaces after End of line but it mixing the contents in format shown below
Code:
000001*    000002  This is line1 and file1 is the actual file. 00003  this is line2  000004  this is line3 end of the file1

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh / AIX - Differences between lists to a text file

This seems pretty simple, but I cant figure it out. I get stumped on the simple things. I am running two commands 1) take a listing a directory of files, and filter out the doc_name (which is in a series of extracted files), and place it in a file. ls -l | awk '{print $9}' | grep... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. UNIX for Beginners Questions & Answers

Compare two big files for differences using Linux

Hello everybody Looking for help in comparing two files in Linux(files are big 800MB each). Example:- File1 has below data $ cat file1 5,6,3 2.1.4 1,1,1 8,9,1 File2 has below data $ cat file2 5,6,3 8,9,8 1,2,1 2,1,4 (8 Replies)
Discussion started by: shanul karim
8 Replies

3. Shell Programming and Scripting

Compare two big files for differences using Linux

Hello everybody Looking for help in comparing two files in Linux(files are big 800MB each). Example:- File1 has below data $ cat file1 5,6,3 2.1.4 1,1,1 8,9,1 File2 has below data $ cat file2 5,6,3 8,9,8 1,2,1 2,1,4 (1 Reply)
Discussion started by: shanul karim
1 Replies

4. Shell Programming and Scripting

Need to compare the two files and list out differences between the two

Hi, I need to compare the two files and list out difference between the two. Please assist. Best regards, Vishal (2 Replies)
Discussion started by: Vishal_dba
2 Replies

5. Shell Programming and Scripting

Merging lines in a text file

hi, I have a file as below: Name: some_name Date: some_date Function Name: <some_function_name(jjjjjjjjj, fjddddd, gggg, ggg)> Changes:<Change A more of change A> Name: some_name Date: some_date Function Name: some_function_nameB(jjjjjjjjj, fjddddd, gggg, ggg) Changes:Change B... (15 Replies)
Discussion started by: flamingo_l
15 Replies

6. HP-UX

Compare 2 systems to find any differences

Hi there, I have 2 machines running HP-UX. One off these controllers is able to send mail and the other cannot. I have looked at all the settings that I know and coannot find any differences. Is there a way to audit the 2 machinces by pulling all the settings then compare any differences? ... (2 Replies)
Discussion started by: lodey
2 Replies

7. Shell Programming and Scripting

Compare two text files and Only show the differences

Hi experts, I'mvery new to shell scripting and learning it now currently i am having a problem which may look easy to u :) i have two files File 1: Start :Thu Nov 19 10:33:09 2009 ABCDGFSDJ.txt APDemoNew.ppt APDemoOutline.doc ARDemoNew.ppt ARDemoOutline.doc File 2: Start... (10 Replies)
Discussion started by: CelvinSaran
10 Replies

8. Shell Programming and Scripting

Compare File Differences in different directories

Hello, I am new to scripting and have been trying to compare two different directories, but with all the same file names in each directory for file changes. I have been doing it in baby steps and have been doing pretty good, but I have hit a few snags. Test 1 and Test 2 work great, but my... (4 Replies)
Discussion started by: dmaday
4 Replies

9. UNIX for Dummies Questions & Answers

Compare 2 files for a single column and output differences

Hi, I have a column in 2 different files which i want to compare, and output the results to a different file. The columns are in different positions in those 2 files. File 1 the column is in position 10-15 File 2 the column is in position 15-20 Please advise Thanks (1 Reply)
Discussion started by: samit_9999
1 Replies

10. Shell Programming and Scripting

merging few columns of two text files to a new file

hi i need to select a few columns of two txt files and write it to a new file. there is one common field for both of these files. plz help me in this thanks in advance (4 Replies)
Discussion started by: kolvi
4 Replies
Login or Register to Ask a Question