diff on c-source file always returns "files differ"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers diff on c-source file always returns "files differ"
# 1  
Old 08-30-2006
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? Smilie
# 2  
Old 08-30-2006
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?
# 3  
Old 08-30-2006
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......
# 4  
Old 08-30-2006
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;
}

# 5  
Old 08-31-2006
$ file main.c
main.c: ascii text


I'll look into the invisible garbage.
# 6  
Old 08-31-2006
MySQL

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.

Smilie Thanks for your help..... Smilie



#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);
}
# 7  
Old 08-31-2006
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?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Help with selecting files from "diff" output

I have two directories Dir_A and Dir_A_Arc. Need help with a shell script. The shell script needs to take the path to these two directories as parameters $1 and $2. The script needs to check if any files exist in these directories and if either of the directories are empty then exit... (5 Replies)
Discussion started by: gaurav99
5 Replies

4. Shell Programming and Scripting

Source command returns error when it strikes conditional statement "ifeq"

Hello All, I am running source command on my project configuration file app.cfg which has conditional statements with make file systax E.g ifeq ($(APP_CMP_DIR),trunk). When I source this file it throws error: syntax error near unexpected token... (1 Reply)
Discussion started by: anand.shah
1 Replies

5. Solaris

Checking RAID health, metastat returns "no database"

Hello, I am supposed to check the RAID health of a system but when I type metastat it says "there are no existing databases" Does this mean that there is no RAID configured at all? Is there any other utility I should try? I know the system has two disks. Tanks! (8 Replies)
Discussion started by: cevspencer
8 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Programming

could not open source file "sys/elf_386.h"

Hello All, i am porting my application from SunSolaris to Linux (RHEL4). When i compile my c/c++ code i am getting the following errors. 1. catastrophic error: could not open source file "sys/elf_386.h" #include <sys/elf_386.h> 2. catastrophic error: could not open source file... (2 Replies)
Discussion started by: tsaravanan
2 Replies

8. UNIX for Dummies Questions & Answers

how to install "source" command!/ broken "login.cl"!

Hello, I am new to this forums and this is my first "asking help" message! i have 2 problems: 1- for unknown reasons the "source" command is not avalable in my system (UBUNTU). i can't either see it in my bin directory! 2- again for unknown reasons the "login.cl" file in the home... (0 Replies)
Discussion started by: astrosona
0 Replies

9. UNIX for Dummies Questions & Answers

Maximum input file size in "Diff" Command

Hello, Can anyone let me know what is the maximum file size that can be given as input for the "Diff" Command in Unix? I have a file size as large as 28MB and which can also increase. Will I face any issues with such a file size. If yes, What is the other alternative. Thanks in advance for... (1 Reply)
Discussion started by: Neeraja
1 Replies

10. Programming

pthread_create returns "operation not permitted" if I try to link static?

Hello, I am trying to port some testtools we wrote from solaris to redhat linux(AMD64). If I link dynamic, set the correct LD_LIBRARY_PATH, everything runs fine. If I try to link static, the pthread_create returns "operation not permitted" (error code 1). Does anybody have an idea where to... (1 Reply)
Discussion started by: Micky
1 Replies
Login or Register to Ask a Question