Skip to content

Instantly share code, notes, and snippets.

@mrdaemon
Created December 15, 2010 22:46
Show Gist options
  • Save mrdaemon/742734 to your computer and use it in GitHub Desktop.
Save mrdaemon/742734 to your computer and use it in GitHub Desktop.
Copy corrupt/missing files from windows sfc log from known good windows 7 install mounted at /media/wsystem. Thank you sfc for creating logs that are impossible to parse without sed grep and awk magic.
grep -i -e "could not" -e "cannot" sfclog.txt | \
awk -F ';' '{ print $1; }' | awk -F "??" '{ print $3; }' | \
sed -e 's/^\\//' -e 's/"\\\[.*\]"/\\/g' -e 's/"$//' | sort | uniq | \
tee -a ./win7sysfiles/FILELIST.TXT | \
sed -e '/^$/d' -e 's/\\/\//g' -e 's/^C:\(.*\)$/\/media\/wsystem\1/' \
-e 's/\([ ()]\)/\\\1/g' | \
while read i ; do if [ -f "$i" ] ; then STATUS="ERROR" ; \
cp "$i" ./win7sysfiles/ && STATUS="COPIED" ; else STATUS="MISSING" ; fi ; \
printf "%-30s%-30s\n" "`basename \"$i\"`" "[$STATUS]" ; done \
&& echo -n "Creating checkums..." ; for f in ./win7sysfiles/* ; do \
md5sum $f > $f.md5sum ; done ; echo "done."
@mrdaemon
Copy link
Author

I originally wrote this crap on a single line. I added lovely linebreaks to make it semi-readable. I'm sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment