From: Lao Ming on
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

This should be easy but I'm encountering something strange and
apparently can't see it.
My command is:

sed "s/^MD5 \(//" |sed "s/\) =//" "$file"

sed: 1: "s/^MD5 \(//": RE error: parentheses not balanced
sed: 1: "s/\) =//": RE error: parentheses not balanced

Thanks for any help. My software versions are below.



bash --version; sw_vers
GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin8.0)
Copyright (C) 2002 Free Software Foundation, Inc.
ProductName: Mac OS X
ProductVersion: 10.4.10
BuildVersion: 8R218

From: Ed Morton on
On Oct 30, 4:05 pm, 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
>
> This should be easy but I'm encountering something strange and
> apparently can't see it.
> My command is:
>
> sed "s/^MD5 \(//" |sed "s/\) =//"  "$file"
>
> sed: 1: "s/^MD5 \(//": RE error: parentheses not balanced
> sed: 1: "s/\) =//": RE error: parentheses not balanced
>
> Thanks for any help.  My software versions are below.
>
> bash --version; sw_vers
> GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin8.0)
> Copyright (C) 2002 Free Software Foundation, Inc.
> ProductName:    Mac OS X
> ProductVersion: 10.4.10
> BuildVersion:   8R218

$ echo "MD5 (./.bashrc) = 92caf5b1a55b3daf31d7616e81c94742" |
sed 's/^MD5 ([^)][^)]*) =//'
92caf5b1a55b3daf31d7616e81c94742

Ed.

From: Seebs on
On 2009-10-30, Lao Ming <laomingliu(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

-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!
From: pk on
Lao Ming 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

in this specific case,

sed 's/.* //'

should do. To keep with what you were trying to do, parentheses in sed are
literal unless escaped, so you probably wanted this:

sed 's/^MD5 ([^(]*) = //'

however that will fail if the string between (....) contains itself a (.

From: Steven J Masta on
Lao Ming 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
>
> This should be easy but I'm encountering something strange and
> apparently can't see it.
> My command is:
>
> sed "s/^MD5 \(//" |sed "s/\) =//" "$file"
>
> sed: 1: "s/^MD5 \(//": RE error: parentheses not balanced
> sed: 1: "s/\) =//": RE error: parentheses not balanced
>
> Thanks for any help. My software versions are below.
>
>
>
> bash --version; sw_vers
> GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin8.0)
> Copyright (C) 2002 Free Software Foundation, Inc.
> ProductName: Mac OS X
> ProductVersion: 10.4.10
> BuildVersion: 8R218
>

Using GNU sed 4.1.5 this works for me:

% cat test.md5
MD5 (./.bashrc) = 92caf5b1a55b3daf31d7616e81c94742
% sed 's/^MD5 (\(.*\)) =/\1/' test.md5
../.bashrc 92caf5b1a55b3daf31d7616e81c94742

Steve