How do a find data in one file, search for it in another file and if not found, write a custom message to another file


in file if.txt, starting on 2nd line of file, data formatted follows:

ah10551,a10551,cn=a10551,a10551@qts.com
ah10600,a10600,cn=a10600,a10600@qts.com
ah10608,a10608,cn=a10608,a10608@qts.com

in file sf.txt, data formatted follows:

2011-02-16 17:26:44 sid acme\ah10551 added sid history of qts\a10551
2011-02-16 17:26:44 sid acme\ah10244 added sid history of qts\a10244
2011-02-16 17:26:45 sid acme\ah10425 added sid history of qts\a10425

please provide suggestions on how following:

1. in if.txt file, read first field first ',' , store in variable called $if1

2. in sf.txt file, search for the value stored in $if1 , if found, ignore.  if not found, write custom message in another file such as: $if1 sidhistory not migrated.

these files wont large.  im trying build 'exception file' of items in if.txt file not occurring in sf.txt file.

thanks in advance ideas.


mtv99

many ways that... here's one... (using example data)

[array]$if1=@()
gc d:\if.txt | select -skip 1 | %{$if1+=($_ -replace '(\w\d),.+','$1')}
$sf=[system.io.file]::readalltext("d:\sf.txt")
$if1 | %{if(!($sf.contains($_))){write-host match not found $_}}

match not found ah10600
match not found ah10608


just humble sysadmin


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered