From: Lao Ming on
On Oct 30, 2:27 pm, Seebs <usenet-nos...(a)seebs.net> wrote:
> On 2009-10-30, Lao Ming <laoming...(a)gmail.com> wrote:
>
> > I'm trying format the output of md5 so it does not contain unneeded
> > punctuation.
> > In particular,  I want to remove "^MD5", the two parens and the equal
> > sign in e.g.
>
> >    MD5 (./.bashrc) = 92caf5b1a55b3daf31d7616e81c94742
>
> To just get the last value:
>
> awk '{print $NR}'
> ${line##*= }
> sed -e 's/.*= //'
>
> Getting the name is a bit trickier.
>
> I'd probably do
> sed -e 's!MD5 (\(.*\)) = \(.*\)!\1 \2!g'
>
> > This should be easy but I'm encountering something strange and
> > apparently can't see it.
>
> Yes.
>
> > sed "s/^MD5 \(//" |sed "s/\) =//"  "$file"
>
> > sed: 1: "s/^MD5 \(//": RE error: parentheses not balanced
> > sed: 1: "s/\) =//": RE error: parentheses not balanced
>
> In sed, ( matches a (, but \( introduces a subexpression (see the
> example above).
>
> Note that there are multiple md5-type utilities, which have slightly
> different output format.  It looks like you're using a BSD-flavored
> "md5" utility.  You might be happier with "md5 -r":
>
> $ md5 -r /tmp/t
> 27a67d2ee992c3bd20cdef673b6cf0ac /tmp/t


Thanks, Seebs. This was perfect! I guess I should have read the man
page but it didn't even occur to me to think I could get simpler
output. Thanks to all other suggestions too. They all worked!


> -s
> --
> Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nos...(a)seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

From: Seebs on
On 2009-11-03, Lao Ming <laomingliu(a)gmail.com> wrote:
> Thanks, Seebs. This was perfect! I guess I should have read the man
> page but it didn't even occur to me to think I could get simpler
> output.

I never knew either, and now I'm thinking of a bunch of places in a
build system I work with that use the Linuxy md5 checksummer and wondering
if it has a similar option.

> Thanks to all other suggestions too. They all worked!

Usenet's like that!

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!