Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 03-26-2010, 02:04 PM   #1
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, 02:54 PM   #2
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)


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

All times are GMT -5. The time now is 08:55 PM.

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