LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
LinkBack 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


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration