The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
total number of files which have "aaa" in files whose names are File*_bbb* sudheshnaiyer UNIX for Dummies Questions & Answers 1 08-16-2007 11:34 AM
Maximum input file size in "Diff" Command Neeraja UNIX for Dummies Questions & Answers 1 01-17-2007 06:09 AM
ps command returns a "?" jxh461 UNIX for Dummies Questions & Answers 6 09-23-2006 04:15 PM
pthread_create returns "operation not permitted" if I try to link static? Micky High Level Programming 1 07-21-2005 04:58 AM
reformat the output from "diff" command CamTu Shell Programming and Scripting 5 03-01-2005 06:54 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-30-2006
Registered User
 

Join Date: Aug 2006
Posts: 5
Question diff on c-source file always returns "files differ"

I have a c-source file that is evidently seen by unix as a binary file. When doing a diff between it and older versions with substantial differences, diff will only return "files differ".

I have tried cat-ing the file to another file; tried using the "-h" on the diff; I have tried ftp-ing it back and forth as ascii; I have played with chmod; I have tried using dos2unix... no matter what I do I can't get Unix to see the file as a text file.


Anybody seen this before... and have a solution?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-30-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Sounds like you've got gremlins. You can use some commands illustrated in that thread to strip out the offending characters.

It's not UNIX that's being stubborn about this, just diff. UNIX has no concept of "text file", everything's just data.

Note that, if it can't diff, it probably can't compile either. Most compilers throw up on high ASCII.

Which file have you been doing all the pounding on? Maybye you're fixing the wrong one, and the gremlin's in the other?
Reply With Quote
  #3 (permalink)  
Old 08-30-2006
Registered User
 

Join Date: Aug 2006
Posts: 5
compile has no problem

I've changed this file quite often and all the versions of it seem to compile without a problem. No visible gremlins......
Reply With Quote
  #4 (permalink)  
Old 08-30-2006
Supporter
 

Join Date: Jul 2006
Posts: 156
What does 'file' say? Also, you could write a small C program to filter any 'gremlin' characters, visible or not.
Code:
$ file Clean.c
Clean.c: ASCII C program text

$ cat Clean.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
main( int argc, char *argv[] )
{
  char c;

  while( (read( STDIN_FILENO , &c , sizeof( char ) )) > 0 )
    if (isprint( c )||isspace(c))
      printf("%c",c);

  return 0;
}
Reply With Quote
  #5 (permalink)  
Old 08-31-2006
Registered User
 

Join Date: Aug 2006
Posts: 5
$ file main.c
main.c: ascii text


I'll look into the invisible garbage.
Reply With Quote
  #6 (permalink)  
Old 08-31-2006
Registered User
 

Join Date: Aug 2006
Posts: 5
Thumbs up

Quote:
Originally Posted by nathan
What does 'file' say? Also, you could write a small C program to filter any 'gremlin' characters, visible or not.
Code:
$ file Clean.c
Clean.c: ASCII C program text

$ cat Clean.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
main( int argc, char *argv[] )
{
  char c;

  while( (read( STDIN_FILENO , &c , sizeof( char ) )) > 0 )
    if (isprint( c )||isspace(c))
      printf("%c",c);

  return 0;
}
I used the following code to wash the problem file. The input file size was 25093, the output file size is 25093.... but the result is now "diff" sees it as text and not binary.

Thanks for your help.....



#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

main()
{
FILE *fpInput, *fdOutput;
char c;

fdOutput = fopen("mainout.c", "w");

fpInput = fopen("main.c", "r");
while (fread(&c, sizeof(char), 1, fpInput) > 0)
{
if(isprint(c) || isspace(c))
fprintf(fdOutput,"%c", c);
}
fclose (fpInput);
fclose (fdOutput);
}
Reply With Quote
  #7 (permalink)  
Old 08-31-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Glad the problem is solved. That they're the same length is very odd -- the only way that program can change the file is by excluding bytes! Thus I have found an exception to what I previously thought was a rule, that UNIX does not differentiate between text and binary files. What UNIX are you using?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:42 AM.


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

Content Relevant URLs by vBSEO 3.2.0