Hi,
I have two files viz,
rak1:
$ cat rak1
rak2:
$ cat rak2
#this is test
[section1]
PMAN 2
ZMAN 9
[section2]
xxx 0
NOTA 5
TOCN 8
[section 3]
PMAN 1
sdiff rak1 rak2
returns:
$ 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:
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
I do not see why you need the egrep. Use sed for that filtering - easy.
Now, using -n option you prevent sed from printing unnessesary line.
After that just print what you need: lines with section number and lines with changes:
> sdiff rak1 rak2 | grep -n "." | sed -n '/>$/d; /section/p; /[|<>]/p'
Ok, deleting still needed
The only not-nice, the sections with no changes will be in that printout
I could not get it by 'sed'
Easy with nawk:
>....|
nawk '{if ( ($0 !~ /section/) || (prev !~ /section/) ) print prev; prev=$0;}
END{if ($0 !~ /section/) print $0;}'
Not clear why it has empty line in beginning and end; so, remove it by :
>...|nawk NF;