The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 01-27-2007
fredao fredao is offline
Registered User
 

Join Date: Dec 2006
Posts: 58
Quote:
Originally Posted by aigles
A possible solution :
Code:
awk 'NR==FNR { keys[$1]++ ; next } $1 in keys' file2 file1

Jean-Pierre.
It works on the above question. however, my real problem is more complicated: the file1 is actually an XML file like this:

...
<object
type="user"
id="000039BF228B"
encryptedPassword=""
maxConnections=""
>
<checkListAttributes>
</checkListAttributes>
</object>

...
<object
type="user"
id="0000E2801BFD"
encryptedPassword=""
>
<checkListAttributes>
</checkListAttributes>
</object>
...

and file2 is a list of id, as:

...
000039BF228B
0000E2801BFD
...

I want to delete all the blocks whose id is not in file2, and keep those with id in file2. I think we can change the RS (record separator to </object>), but I do not know how to do the whole job. would you help again?
Reply With Quote