The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
diff file and previous version bigboizvince Shell Programming and Scripting 1 03-26-2008 03:55 AM
Copy data and send it to other file, with diff config single Shell Programming and Scripting 0 01-29-2008 06:56 AM
File Compare and Create New File with Diff guiguy UNIX for Advanced & Expert Users 7 02-28-2007 03:43 AM
Help with multiple file rename - change case of part of file name steve7 UNIX for Dummies Questions & Answers 7 06-30-2005 10:41 AM
diff 2 files; output diff's to 3rd file blt123 Shell Programming and Scripting 2 05-28-2002 08:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 31
Exclamation diff part of file

Hello experts,
I have 2 files
file1:
lalalala good file

file2:
lblblblb good file

these two files are the same in my test case, how can I start compare after certain number of characters? or is there a better way to do this?

Thank you

Last edited by minifish; 02-20-2008 at 09:49 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 02-20-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 982
Question Need more info

Are the files all in one line?

You ask about comparing files after a certain number of characters, so are you looking to ignore a fixed number characters on each line for each file?

If those are the 'true' files, then a solution could be proposed.
However, if there is more to the samples, it would be helpful to see.
Reply With Quote
  #3  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 31
Quote:
Originally Posted by joeyg View Post
Are the files all in one line?

You ask about comparing files after a certain number of characters, so are you looking to ignore a fixed number characters on each line for each file?

If those are the 'true' files, then a solution could be proposed.
However, if there is more to the samples, it would be helpful to see.
The files contain more than 1 line, a more likely example would be:

file1:
lalalala good file
lalblala good file
lalalalb good file
lalalbla good file

file2:
lblblblb good file
lblblclb good file
lblclblb good file
lclblblb good file

compare:
#file1 and file2 are the same

so I want to start compare after say 8 characters on every line in the two files.
Reply With Quote
  #4  
Old 02-20-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 982
Wink one approach

I created two sample files (note I purposefully made a difference in the 2nd file calling something bad instead of good - to see some output from a diff command)
Code:
> cat tfile1
lalalala good file
lalblala good file
lalalalb good file
lalalbla good file
> cat tfile2
lblblblb good file
lblblclb good file
lblclblb good file
lclblblb bad file
then, using the following script:
Code:
> cat cfile
#! /bin/bash

f1="tfile1"
f2="tfile2"
f1out=$f1".out"
f2out=$f2".out"

cat tfile1 | cut -c10- >$f1out
cat tfile2 | cut -c10- >$f2out

diff $f1out $f2out
results in:
Code:
> cfile
4c4
< good file
---
> bad file
Reply With Quote
  #5  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 31
Quote:
Originally Posted by joeyg View Post
I created two sample files (note I purposefully made a difference in the 2nd file calling something bad instead of good - to see some output from a diff command)
Code:
> cat tfile1
lalalala good file
lalblala good file
lalalalb good file
lalalbla good file
> cat tfile2
lblblblb good file
lblblclb good file
lblclblb good file
lclblblb bad file
then, using the following script:
Code:
> cat cfile
#! /bin/bash

f1="tfile1"
f2="tfile2"
f1out=$f1".out"
f2out=$f2".out"

cat tfile1 | cut -c10- >$f1out
cat tfile2 | cut -c10- >$f2out

diff $f1out $f2out
results in:
Code:
> cfile
4c4
< good file
---
> bad file
Sorry, can't express enough of my thanks~~~~~~
I was stuck on it for so long.
THANK YOU
Reply With Quote
  #6  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 31
one interesting thing is using "cat tfile1 | cut -c10- >$f1out "
tfile1 and f1out must be different.
is there any way to replace the same file?
what about "sed"?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0