Parsing the Windows sfc log from unix

Just a quick line to mention that the Windows System File Checker tool produces logs that are nearly unreadable, and a pain to parse.

A friend of mine had some system files that did not check out, and could not be repaired. After confirming we both ran the same version down to the same patchlevel of Windows 7, he asked if I could send the original files his way, providing me only with the output of

findstr /C:"[SR]" %windir%\logs\cbs\cbs.log >sfcdetails.txt

Of course, I indulged.

The following one bash one liner from hell occured:

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."

view raw copysfc.sh This Gist brought to you by GitHub.

Horrible, yet probably semi-useful to someone.

You might also enjoy:

About Alexandre Gauthier

A freelance network guy, sometimes programmer and overall tinkerer. Said to be a decent writer, in both english and en français. Wears fancy pants with torn t-shirts on sundays. Enjoys writing long, vitriolic diatribes and short stories. Lives inside a unix shell, favorite text editor is vim.
This entry was posted in Computers, Unix/Linux, Windows and tagged , , , , . Bookmark the permalink.

One Response to Parsing the Windows sfc log from unix

  1. Marc says:

    Salut Alex,

    check tes e-mail!!!

    Marc

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">