File Comparison command but ignoring while spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Comparison command but ignoring while spaces
# 1  
Old 07-09-2009
File Comparison command but ignoring while spaces

Hello All,

I am writing a file comparison utility and using the cmp command to compare 2file. But I need command that will compare 2 files and if the files are identical expect for differences in white spaces, then it should ignore those spaces and consider the two files equal. Is there a way to achieve this via shell scripting or a unix command?


Please help.

Thanks in advance.
# 2  
Old 07-09-2009
you might be better served by the diff command.

diff -b in particular should be close to where you need to be.

HTH
# 3  
Old 07-09-2009
I have tried both diff -bew but none seem to serving the purpose..any other suggestions are eargerly awaited.
# 4  
Old 07-09-2009
Or?
diff -w

---------- Post updated at 01:52 PM ---------- Previous update was at 01:34 PM ----------

If all you want to know is whether the files are different or not, test the reply code from "diff -w". The reply is "0" if they are identical after ignoring white space. The reply is "1" if they are different after ignoring white space.

Code:
diff -w file1 file2 >/dev/null;REPLY=$?
if [ ${REPLY} -eq 0 ]
then
         echo "Files are identical"
else
         echo "Files are different"
fi

# 5  
Old 07-10-2009
That too doesnt seem to work, it gives a messages files are identical althrough the size of both the files are different Smilie Please help is there any other way I can exclude the whitespaces??
# 6  
Old 07-10-2009
Quote:
That too doesnt seem to work, it gives a messages files are identical althrough the size of both the files are different
This is at odds with your original requirement/question.
# 7  
Old 07-10-2009
The difference in size is due to white spaces in one of the file. There are extra lines added as white spaces but the code in both the file is exactly the same.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate lines after ignoring case and spaces between

Oracle Linux 6.5 $ cat someStrings.txt GRANT select on MANHPRD.S_PROD_INT TO OR_PHIL; GRANT select on MANHPRD.S_PROD_INT TO OR_PHIL; GRANT select on SCOTT.emp to JOHN; grant select on scott.emp to john; grant select on scott.dept to hr;If you ignore the case and the empty space between the... (6 Replies)
Discussion started by: kraljic
6 Replies

2. UNIX for Advanced & Expert Users

Tcl script for seaching a string ignoring white spaces

Hi , I want to search a string in a file ignoring white spaces in TCL. My string is as follows Ouput-Maps " 1 1 1 0 " 1i am doing following set a *1*1*1*0* " }1 abc.log}] but it is not working. What is the wrong with the tcl script Thanks Gouranga Video... (0 Replies)
Discussion started by: mybapa3000@gmai
0 Replies

3. Post Here to Contact Site Administrators and Moderators

Want a tcl script to compare a string in a file ignoring white spaces

Hi , I want a tcl script to search a string ignoring whitespaces in a .log file . It should correctly match . The string are as follows "Output-Maps 1 1 0 0 0" 1 and Active Intermediate-Maps 0 0 0 ... (1 Reply)
Discussion started by: kulua
1 Replies

4. Shell Programming and Scripting

ignoring lines in a file

HI, command to cat a readable file by ignoring the first line and last line or command to cat a readable file by ignoring the lines with delimiter Please advise on this. (2 Replies)
Discussion started by: thelakbe
2 Replies

5. UNIX for Dummies Questions & Answers

Several file comparison not uniq or comm command

When comparing several files is there a way to find values unique to each file? File1 a b c d File2 a b t File 3 a (3 Replies)
Discussion started by: dr_sabz
3 Replies

6. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

7. Shell Programming and Scripting

How to ignore the Spaces while string Comparison

I want to ignore the spaces while doing string comparison between two files. Iam using "comm" command to compare the files. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

8. Shell Programming and Scripting

"read" command ignoring leading spaces

I have to read a file line by line, change it and then update the file. Problem is, when i read the file, "read" command ignores leading spaces. The file is a script which is indented in many places for clarity. How to i make "read" command read leading spaces as well. (3 Replies)
Discussion started by: vickylife
3 Replies

9. UNIX for Dummies Questions & Answers

ignoring a dash in file name

so i have a simple file called -x and i need it renamed to x now i dont understand why when using the most basic methods, only the code mv ./-x x changes the file name while using any other type of escape characters around the dash, such as single/double quotations or backslash, doesnt. ... (5 Replies)
Discussion started by: LumpSum
5 Replies

10. Shell Programming and Scripting

ignoring backslash while executing command

Hi, I'm running into following issue, my_file is a collection of windows directories (i.e \\path\directory\file) . I need to be able to execute "my command" as my command \\path\directory\file I know that while read -r / print -r ignores backslashes. My code: cat $my_file | while read -r... (6 Replies)
Discussion started by: agalkin
6 Replies
Login or Register to Ask a Question