Help needed for diff to ignore a line with certain pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed for diff to ignore a line with certain pattern
# 1  
Old 10-01-2011
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 command to ignore these first lines in both files.


For e.g -

PHP Code:
File 1 

Abcd
test1
test2
test3


File 2 


Abcfdfd
test1
test2
test3 
Now, I am trying to use
PHP Code:
diff -ty --"^Abc" file1 file2 file3 
Here, I am trying to use a ignore flag for diff to ignore lines in both files that start with "Abc" however, I keep getting syntax errors for diff saying - Try diff --help for more information.

Can someone please tell me how do I make the above happen? Any help is greatly appreciated -

Cheers,
Morgan
# 2  
Old 10-01-2011
It works fine in my GNU diff in Cygwin:

Code:
$
$
$ cat file1
Abcd
test1
test2
test3
$
$ cat file2
Abcfdfd
test1
test2
test4
$
$
$ diff -ty -B file1 file2
Abcd                                                            |  Abcfdfd
test1                                                              test1
test2                                                              test2
test3                                                           |  test4
$
$
$ diff -ty -B -I "^Abc" file1 file2
Abcd                                                               Abcfdfd
test1                                                              test1
test2                                                              test2
test3                                                           |  test4
$
$ diff --version
diff (GNU diffutils) 2.9
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Eggert, Mike Haertel, David Hayes,
Richard Stallman, and Len Tower.
$
$

Maybe your diff or system is different?

tyler_durden
# 3  
Old 10-03-2011
I have a diff version as 2.8.1 and OS is RHEL 5.2

Am checking further and would let you know shortly.

Thanks,
Morgan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

How to ignore comments at the end of the each line?

Hi All, I am reading the host file by ignoring the comments and write it to the other file. I am reading with regular expression for IP address. grep -E '^{1,3}\.{1,3}\.{1,3}\.{1,3}' $inputFile | awk '{for(i=2;i<=NF;i++)print $1,$i}' > $DR_HOME/OS/temp After that am reading each host... (4 Replies)
Discussion started by: sharsour
4 Replies

4. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

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

6. Shell Programming and Scripting

awk : ignore first 5 line and last line of a file

Hi All, I have text file like as below temp.txt 1 Line temp.txt 2 Line temp.txt 3 Line temp.txt 4 Line temp.txt 5 Line temp.txt 6 Line temp.txt 7 Line temp.txt 8 Line temp.txt N Line I expect the output like as below processing 6 ... processing 7 ... (6 Replies)
Discussion started by: k_manimuthu
6 Replies

7. UNIX for Advanced & Expert Users

Script to ignore word from a line ...

Hi Gurus, I'm need of a script in which we are finding an independent word ‘boy' in a log file. We are using grep in order to do the same. Now in this log file there are some sentences where we see ‘This is a boy' and we do not want to count word ‘boy' from this sentence. So in other word we want... (2 Replies)
Discussion started by: heyitsmeok
2 Replies

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

9. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: sksahu
1 Replies

10. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies
Login or Register to Ask a Question