LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 10-01-2011, 03:30 PM   #1
rockf1bull
LQ Newbie
 
Registered: Feb 2011
Posts: 19

Rep: Reputation: 0
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
 
Old 10-01-2011, 05:40 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,506

Rep: Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618
--edit-

Last edited by John VV; 10-01-2011 at 05:44 PM.
 
Old 10-02-2011, 11:24 PM   #3
rockf1bull
LQ Newbie
 
Registered: Feb 2011
Posts: 19

Original Poster
Rep: Reputation: 0
Hello,

Can someone please shed some light onto this?

Cheers,
Morgan
 
Old 10-02-2011, 11:36 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,469

Rep: Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453Reputation: 3453
Nope. Works for me.
Distro ?. bash/diff versions ?.
 
Old 10-03-2011, 01:18 AM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,506

Rep: Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618Reputation: 2618
what version of diff ? and on what distro ?and i take it you have read the man page and the info page
 
Old 10-03-2011, 02:09 AM   #6
rockf1bull
LQ Newbie
 
Registered: Feb 2011
Posts: 19

Original Poster
Rep: Reputation: 0
I have a diff version of 2.8.1 and OS is RHEL 5.2

I will above things tho and yes, I have indeed gone through the man and info pages.

Thanks very much for your suggestions.

Cheers,
Morgan
 
Old 10-04-2011, 12:41 PM   #7
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 609

Rep: Reputation: 66
dunno, mine looks ok.

can you post the output of the commands i did. i know you cant get get file3 data if you keep getting syntax error. please post the error line.

Code:
[]$ more redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)

[]$ uname -a
Linux 2.6.18-274.3.1.el5 #1 SMP Fri Aug 26 18:45:04 EDT 2011 i686 i686 i386 GNU/Linux

[]$ rpm -qa |grep "bash\|diff"
bash-3.2-32.el5
diffutils-2.8.1-15.2.3.el5

[]$ more file1 file2
::::::::::::::
file1
::::::::::::::
Abcd
test1
test2
test3
::::::::::::::
file2
::::::::::::::
Abcfdfd
test1
test2
test3


[]$ diff -ty -B -I "^Abc" file1 file2 > file3;cat file3
Abcd                                                               Abcfdfd
test1                                                              test1
test2                                                              test2
test3                                                              test3

[]$ hexdump -C file1
00000000  41 62 63 64 0a 74 65 73  74 31 0a 74 65 73 74 32  |Abcd.test1.test2|
00000010  0a 74 65 73 74 33 0a                              |.test3.|
00000017

[]$ hexdump -C file2
00000000  41 62 63 66 64 66 64 0a  74 65 73 74 31 0a 74 65  |Abcfdfd.test1.te|
00000010  73 74 32 0a 74 65 73 74  33 0a                    |st2.test3.|
0000001a

[]$ hexdump -C file3
00000000  41 62 63 64 20 20 20 20  20 20 20 20 20 20 20 20  |Abcd            |
00000010  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000040  20 20 20 41 62 63 66 64  66 64 0a 74 65 73 74 31  |   Abcfdfd.test1|
00000050  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000080  20 20 20 20 20 20 20 20  20 20 20 20 20 20 74 65  |              te|
00000090  73 74 31 0a 74 65 73 74  32 20 20 20 20 20 20 20  |st1.test2       |
000000a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000000d0  20 20 20 20 20 20 20 74  65 73 74 32 0a 74 65 73  |       test2.tes|
000000e0  74 33 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |t3              |
000000f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000120  74 65 73 74 33 0a                                 |test3.|
00000126

Last edited by Linux_Kidd; 10-04-2011 at 12:53 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed to display the pattern string, the line above it and the first line of that para rockie321 Linux - Newbie 3 04-03-2011 03:48 PM
multiple pattern search in a single file line by line saheervc Linux - Newbie 2 09-02-2010 12:45 AM
setting IFS to ignore pattern eRJe Programming 3 03-12-2010 05:20 AM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 07:17 AM
delete a line containing a pattern and the next line of a text file powah Programming 3 01-31-2007 06:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 01:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration