The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-23-2008
rakeshou rakeshou is offline
Registered User
  
 

Join Date: May 2007
Posts: 75
Thumbs up Finding Last occurance of another pattern when a pattern is found.

Hi,

I have two files viz,

rak1:
$ cat rak1
Quote:
#this is test

[section1]
PMAN 2
ZMAN 4

[section2]
xxx 0
NOP 6

[section 3]
PMAN 1
ZMAN 8
rak2:

$ cat rak2
Quote:
#this is test

[section1]
PMAN 2
ZMAN 9

[section2]

xxx 0
NOTA 5
TOCN 8






[section 3]
PMAN 1
Code:
sdiff rak1 rak2
returns:

Quote:
$ sdiff rak1 rak2
#this is test #this is test

[section1] [section1]
PMAN 2 PMAN 2
ZMAN 4 | ZMAN 9

[section2] [section2]
>
xxx 0 xxx 0
NOP 6 | NOTA 5
> TOCN 8

>
>
>
>
>
[section 3] [section 3]
PMAN 1 PMAN 1
ZMAN 8 <
I want the lines that got modified, changed, or deleted preceding with the section they are in.

I have done this so far:

Quote:
$ sdiff rak1 rak2 | sed 's/ //g' | grep -n "." | egrep -e "\||<|>" | sed '/>$/d'
5:ZMAN 4 |ZMAN 9
10:NOP 6 |NOTA 5
11:>TOCN 8
20:ZMAN 8 <
but I dont know how to put section in front of the changed,added or deleted lines.

Also it would be appreciated if the output could be printed as

[section X] <valInFile1/valInFile2> <valInFile1/valInFile2>
and so on.



Please Help me out