Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Compare and merging the differences in text file Post 302572912 by rakeshkumar on Friday 11th of November 2011 04:55:44 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
DIFF3(1)						      General Commands Manual							  DIFF3(1)

NAME
diff3 - 3-way differential file comparison SYNOPSIS
diff3 [ -ex3 ] file1 file2 file3 DESCRIPTION
Diff3 compares three versions of a file, and publishes disagreeing ranges of text flagged with these codes: ==== all three files differ ====1 file1 is different ====2 file2 is different ====3 file3 is different The type of change suffered in converting a given range of a given file to some other is indicated in one of these ways: f : n1 a Text is to be appended after line number n1 in file f, where f = 1, 2, or 3. f : n1 , n2 c Text is to be changed in the range line n1 to line n2. If n1 = n2, the range may be abbreviated to n1. The original contents of the range follows immediately after a c indication. When the contents of two files are identical, the contents of the lower-numbered file is suppressed. Under the -e option, diff3 publishes a script for the editor ed that will incorporate into file1 all changes between file2 and file3, i.e. the changes that normally would be flagged ==== and ====3. Option -x (-3) produces a script to incorporate only changes flagged ==== (====3). The following command will apply the resulting script to `file1'. (cat script; echo '1,$p') | ed - file1 FILES
/tmp/d3????? /usr/lib/diff3 SEE ALSO
diff(1) BUGS
Text lines that consist of a single `.' will defeat -e. Files longer than 64K bytes won't work. DIFF3(1)
All times are GMT -4. The time now is 11:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy