LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-26-2010, 01:04 PM   #1
jedibrand
LQ Newbie
 
Registered: Mar 2009
Posts: 7

Rep: Reputation: 0
How to compare/diff a range of lines from two text files


i tried using diff --GTYPE-group-format= with <%, but not sure that's the right solution.

Here's what im trying to do. I have two c source files, file1 and file2. file1 has a function in it that's been modified in file2. However, the functions begin at differnt line numbers in eachof the files. Is there a way to specify a range of file numbers on file1 and file2 to compare, using diff or any other combination of utilities?

I can always output text from a range of lines from each file to two separate and new files and then compare those, but that's tedious. I could also write up a script to automate this type of solution, but I imagine there's an existing way of doing this.
 
Old 03-26-2010, 01:54 PM   #2
jedibrand
LQ Newbie
 
Registered: Mar 2009
Posts: 7

Original Poster
Rep: Reputation: 0
I think I just put together a working solution, a combination of other existing, similar solutions:

diff <(grep-w FileA | sed -n '21,51p' file1) <(grep-w FileB | sed -n '120,147p' file2)
 
  


Reply



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
compare two files and print the same text kariagekun Linux - Newbie 4 10-14-2009 07:24 AM
bash- how to compare only certain lines of text files daberkow Linux - Newbie 2 06-01-2009 04:48 PM
Diff compare 2 files DavidTempler Linux - Newbie 2 11-01-2004 10:00 AM
how to compare 2 text files by using php code antony_csf Programming 3 10-14-2004 05:52 AM
Using diff to compare file with common lines, but at different line numbers jimieee Linux - Newbie 3 05-10-2004 07:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:52 AM.

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