Find difference in content between two particular lines in two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find difference in content between two particular lines in two files
# 1  
Old 09-05-2013
Find difference in content between two particular lines in two files

I have two files named Before.txt and After.txt:

Quote:
Before.txt:
--- --- ---
--- --- ---
<Marker 1>
--- --- --- --
--- --- --- --
--- --- --- --
<Marker 2>
--- --- ---
--- --- ---

After.txt:
--- --- ---
--- --- ---
<Marker 1>
--- --- --- --
--- --- --- --
--- --- --- --
<Marker 2>
--- --- ---
--- --- ---
Now i want to find the difference in content between <Marker 1> and <Marker 2> in the two files.

---------- Post updated at 05:00 PM ---------- Previous update was at 04:50 PM ----------

Any help will be highly appreciated..Smilie
# 2  
Old 09-05-2013
Using diff with process substitution:

Code:
$ diff <(sed -n '/<Marker 1>/,/<Marker 2>/p' before.txt) <(sed -n '/<Marker 1>/,/<Marker 2>/p' after.txt)

# 3  
Old 09-07-2013
Thanks, but how can i get only the content between the two markers, in the above case the markers also come in the output.
# 4  
Old 09-07-2013
Hello,

You must just modify the 2 sed command like:
Code:
sed -n '/<Marker 1>/,/<Marker 2>/{/<Marker 1>\|<Marker 2>/!p}'

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. UNIX for Advanced & Expert Users

Find difference between 2 files

I have 2 files as follows. file1.txt <cell>123</cell> <cell>345</cell> file2.txt <cell>123</cell> <cell>456</cell> out out should be output.txt <cell>456></cell> How do we achieve this> The difference betwenn the two files should be wirtten to the output file.. ... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

3. Shell Programming and Scripting

Find time difference between two consecutive lines in same file.

Hello I have a file in following format: IV 08:09:07 NM 08:12:01 IC 08:12:00 MN 08:14:20 NM 08:14:15 I need a script to compare time on each line with previous line and show the inconsecutive line. Ex.: 08:12:00 08:14:15 A better way... (6 Replies)
Discussion started by: vilibit
6 Replies

4. UNIX for Dummies Questions & Answers

Find difference between two files

I have two files as below File1: a b c d File2: a b When i find the difference the output would be c&d.. How can i get my requirement...pls help... Many thanks in advance (10 Replies)
Discussion started by: jagadish_gaddam
10 Replies

5. Solaris

Need help to find difference between two files

I need to find the difference between two files in UNIX. I tried diff, but couldn't get it right. There are two files: file1: apple mango strawberry banana grape file2: grape apple banana I need an output file like below: ... (11 Replies)
Discussion started by: kisaad
11 Replies

6. Emergency UNIX and Linux Support

to find difference between two files

I have a file which gets appended with records daily..for eg. 1st day of the month i get 9 records ,2nd day 9 records .....till the last day in the month...the no of records may vary...i store the previous days file in a variable oldfile=PATH/previousdaysfile....i store the current days file in a... (6 Replies)
Discussion started by: ganesh_248
6 Replies

7. Shell Programming and Scripting

Help to find the time difference between the lines

Hi guru's, Am new to shell scripting. I am getting the below o/p from the oracle database, when I fire a query. ID JOB_ID ELAPSED_TIME FROM TO ----- ------ ------------------- -------- -------- 62663 11773 01/06/2009 09:49:13 SA CM 62664 11773 ... (4 Replies)
Discussion started by: sathik
4 Replies

8. Shell Programming and Scripting

Compare two files and print the two lines with difference

I have two files like this: #FILE 1 ABCD 4322 26485 JMTJ 5311 97248 XMPJ 4321 58978 #FILE 2 ABCD 4321 26485 JMTJ 5311 97248 XMPJ 4321 68978 What to do: Compare the two files and find those lines that doesn't match. And have a new file like this: #FILE 3 "from file 1" ABCD 4322 26485... (11 Replies)
Discussion started by: kingpeejay
11 Replies

9. Shell Programming and Scripting

To find the time difference between two lines of the same log file

Hello Friends, I want to write a script for the following: nlscux62:tibprod> grep "2008 Apr 30 01:" SA_EHV_SPEED_SFC_IN_03-SA_EHV_SPEED_SFC_IN_03-2.log | grep -i post | more 2008 Apr 30 01:01:23:928 GMT +2 SAPAdapter.SA_EHV_SPEED_SFC_IN_03-SA_EHV_SPEED_SFC_IN_03-2 Info AER3-000095 IDOC... (2 Replies)
Discussion started by: satyakam
2 Replies

10. Shell Programming and Scripting

I want to record the difference in the content of files in different directory

Hi All I am very new to the Unix shell scripting ,, could you pleae help me to generate the output file having the filename and path which files having the difference in the contents in the two directory. all files in both directory have the same name and format. input directory /edc/input1/ ... (3 Replies)
Discussion started by: singhald007
3 Replies
Login or Register to Ask a Question