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
# 15  
Old 11-09-2011
hmmm.. i tried my luck with gawk and also swapping the both files ,
i am using Suse . is it possible to install nawk on Suse , i browsed said nawk for solaries is gawk or awk

can you please tell me the version of nawk you using will that make any difference ?
# 16  
Old 11-09-2011
You have suse, therefore your awk is gawk by default.

---------- Post updated at 08:58 AM ---------- Previous update was at 08:57 AM ----------

Did you try removing carriage returns like he suggested?
# 17  
Old 11-09-2011
Quote:
Originally Posted by rakeshkumar
hmmm.. i tried my luck with gawk and also swapping the both files ,
i am using Suse . is it possible to install nawk on Suse , i browsed said nawk for solaries is gawk or awk

can you please tell me the version of nawk you using will that make any difference ?
gawk should be fine.
The file2.txt that you posted does have ^M-s at the end of the lines.
I'm not sure if it's the result of ftp and attaching to this thread or not...
Follow the directions above to remove ^M-s from the ORIGINAL files you're using.
# 18  
Old 11-09-2011
woww it worked after doing
Code:
 tr -d '\015' < oldfile > newfile

on both files

what exactly is "^M-s" you asked me to check at the end of the lines ?

i greatly appreciate your help and patience ... Smilie
# 19  
Old 11-09-2011
They are these.
These forums contain wealth of the information - start using the 'Search' functionality.
Good to hear it's worked out for you.
This User Gave Thanks to vgersh99 For This Post:
# 20  
Old 11-09-2011
thanks a ton Vgersh

it finally worked and now i will implement this on complete folder which contain 90+ files ,


there is one more issue i have with my job , lets assume if the change is there in 2 continuous lines then
** my change start point **
line x
** my change end point **
** my change start point ** line x+1
** my change end point **
is it possible to write the tags only once as below output
** my change start point **
line x
line x+1
** my change end point **

i got an alternative as am not expert in awk

1) with the output of the above i will search for the lines below and delete them , this can be alternative if the awk does not permit me
** my change end point **
** my change start point **

vgersh please suggest your opinion

thank you !!

Last edited by rakeshkumar; 11-09-2011 at 01:35 PM..
# 21  
Old 11-09-2011
Code:
BEGIN {
  tab=sprintf("\t")
  space="([ ]*|" tab "*)"
}
FNR==NR{f2[FNR]=$0;next}
{
  s1=$0; s2=f2[FNR]
  gsub(space, "",s1);gsub(space, "",s2)
  if ( s1 == s2) {
      if (sep) {
        print e ORS $0
        sep=0
      }
      else print $0
  }
  else {
      if (!sep) {
         print s
         sep++
      }
      printf("*%s\n%s\n", f2[FNR],$0)
  }
}
END {
  if (sep)
    print e
}


Last edited by vgersh99; 11-09-2011 at 02:50 PM.. Reason: forgot the END block
 
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