RE: Using one file to edit a second file.

"Rakesh Sharma [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
If you must do it with "sed" then you could take the following route:
Assuming that all lines in both files have the same format, i.e., the IP numberwe will place an empty line at the end of File2. Then read in the whole of File2first into the hold area. Then after the File2 has been fully read in (signaled by thereading in of the dummy empty line we ourselves placed at File2 end) we shall compare the incoming lines in the pattern space (File1) with the ones in the hold to determine whetherit needs to be retained/discarded.
The above gets translated as below  (untested..) You must test it for syntax/corner cases....
sed -ne '# read in the whole of File2 first into the hold area/./!bfile1H;1h;d
# now read in the File1:file1n;G# PS => ip\nip1\nip2\n...\nipzy/\n_/_\n//^\([_]*\).*_\1_/d/^\([_]*\).*_\1$/dy/\n_/_\n/P;bfile1' File2 File1
HTH
-Rakesh
To: [email protected]
From: [email protected]
Date: Mon, 3 Nov 2014 04:58:07 -0800
Subject: Using one file to edit a second file.














 

 



  


    
      
      
      Im sitting in class right now .. so I cant provide an example. 





But .. I have two files. 





FIle1


10.10.10.2


10.10.10.4


10.10.10.6


10.10.10.8


10.10.10.10





File2 


10.10.10.1


10.10.10.2


10.10.10.3


10.10.10.4


10.10.10.5


10.10.10.6


10.10.10.7


10.10.10.8


10.10.10.9


10.10.10.10





I want to use file one to search file two. If ips in file one are matched in file2, I want to delete them and write a file of non matched ips 





10.10.10.1


10.10.10.3


10.10.10.5


10.10.10.7


10.10.10.9





ofcourse there are special considerations 10.10.10.1, 10.10.10.10, 10.10.10.100 .. need exact matches. 





I could do with is if or case statements .. but just wondering if sed can do it. 





THanks for the help.



[Non-text portions of this message have been removed]






    
     

    
    






   		 	   		  

[Non-text portions of this message have been removed]



------------------------------------

------------------------------------

-- 

------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/sed-users/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/sed-users/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/us/yahoo/utos/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.