I have been struggling quite a bit with something that seemed simple enough (well, relative to sed that is). I want to extract the second "x:...." up to the next "x:..".
Have a look at this (run from sh):
Code: Select all
> echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed 's/x:[a-z\/]*x:ghi\([^:]*\)\/x:.*/\1/'
x:abc/def/x:ghi/jkl/x:mno/pqr
(match (or print) failed)
> echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed 's/x:[a-z\/]*x:ghi\([^:]*\)\/x:.*/\1 /'
/jkl
(I got my output but it has a trailing space)
Now using -re to simplify things:
Code: Select all
> echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed -re 's/x:[a-z\/]+x:ghi([^:]+)\/x:.*/\1/'
/jklno/pqr
(what happened here?? (if I add a space aroung \1 it's fine))
> which sed
Project:SDK/Local/C/sed
> sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.