Ignore a string pattern while doing file comparison/difference


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Ignore a string pattern while doing file comparison/difference
# 1  
Old 06-03-2009
Ignore a string pattern while doing file comparison/difference

Here is my problem. I have to find the differences in 2 XML files

This is my Old File contents - File1
<FILEHDR>
<Bag xsi:nil='true'></Bag>
</FILEHDR>

This is my New File contents - File2
<FILEHDR>
<Bag xsi:nil='true' ></Bag>
</FILEHDR>

When I do the following
diff -b File1 File2

Even though I used the -b option to ignore the amount of white spaces, I get this difference, as there is an extra space after xsi:nil='true' in my new file.

How can I avoid this particular pattern xsi:nil='true' while doing difference of the files ?

Overall I wanted to figure out how can I avoid a pattern while doing comparison/difference of 2 files.

Appreciate your help

Last edited by sksahu; 06-03-2009 at 06:39 PM..
# 2  
Old 06-04-2009
manpages are your friend. Smilie
Code:
$ man diff
DIFF(1)                          User Commands                         DIFF(1)



NAME
       diff - compare files line by line

SYNOPSIS
       diff [OPTION]... FILES

DESCRIPTION
       Compare files line by line.

       -i  --ignore-case
              Ignore case differences in file contents.

       --ignore-file-name-case
              Ignore case when comparing file names.

       --no-ignore-file-name-case
              Consider case when comparing file names.
       -E  --ignore-tab-expansion
              Ignore changes due to tab expansion.

       -b  --ignore-space-change
              Ignore changes in the amount of white space.

       -w  --ignore-all-space
              Ignore all white space.

       -B  --ignore-blank-lines
              Ignore changes whose lines are all blank.

       -I RE  --ignore-matching-lines=RE
              Ignore changes whose lines all match RE.

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk string comparison unterminated quoted string andrule of thumb

I have the logic below to look up for matches within the columns between the two files with awk. In the if statement is where the string comparison is attempted with == The issue seems to be with the operands, as 1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies

2. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

3. Shell Programming and Scripting

Ignore case in awk while pattern searching

Hi , I have the file where i have to search for the pattern. The pattern may be lower case or upper case or camel case. Basically I want to ignore while searching the pattern in awk. awk '/error|warning/exception/' filename Please help me (3 Replies)
Discussion started by: arukuku
3 Replies

4. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. Shell Programming and Scripting

Help needed for diff to ignore a line with certain pattern

Hello Guys, I request anyone to do me a small help in using diff command for following. I am trying to compare two files for content and wish to keep the content after the comparison (The resultant file can't be blank) However, the first lines would be different in both files and I need diff... (2 Replies)
Discussion started by: rockf1bull
2 Replies

6. Shell Programming and Scripting

Three Difference File Huge Data Comparison Problem.

I got three different file: Part of File 1 ARTPHDFGAA . . Part of File 2 ARTGHHYESA . . Part of File 3 ARTPOLYWEA . . (4 Replies)
Discussion started by: patrick87
4 Replies

7. Shell Programming and Scripting

ls ignore pattern

Hi, I have a FTP script that check for ".done" files in the remote path and the "get" the corresponding data files. Here's how it does..... First it list all the *.done file as below: ls *.done And then it picks one file and get the corresponding data file. After that it... (3 Replies)
Discussion started by: dips_ag
3 Replies

8. Shell Programming and Scripting

String comparison: All lines in file but each within line

Hi folks, I'm trying to do a bit of extra monitoring on who is sending mail through our server and as I'm sure you'll understand, the log files aren't exactly small. As a note, I'm working to sort out a solution to this myself, so I'll keep editing the post when I get a chance. Here an example... (2 Replies)
Discussion started by: beddo
2 Replies

9. 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

10. Shell Programming and Scripting

Ignore some lines with specific words from file comparison

Hi all, I need help in doing this scenario. I have two files with multiple lines. I want to compare these two files but ignoring the lines which have words like Tran, Loc, Addr, Charge. Also if i have a word Credit in line, i want to tokenize (i.e string after character " ... (2 Replies)
Discussion started by: jakSun8
2 Replies
Login or Register to Ask a Question