Re: Problem with positional output

"Stephane Chazelas [email protected] [sed-users]" <[email protected]> Mon, 14 Nov 2016 13:55:43 +0000
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
2016-11-14 14:03:50 +0100, Michelle Konzack [email protected] [sed-users]:
[...]
> The string has 4 parameters, deperated by the | sign and I like  to  get
> it with something like
> 
> 
>      echo "${RETVAL}" |sed 's!(.*)|(.*)|(.*)!$1!'
[...]

You don't have to use sed for that (which by the way wouldn't
work here if the "parameters" contain newline characters). You
can use the shell's (sh) split+glob operator:

IFS='|'        # split on |
set -o noglob  # disable glob
set -- $RETVAR # use split+glob to assign the $1, $2... parameters

printf '%s\n' "$1" # first parameter. You can't use echo for
		   # arbitrary data

-- 
Stephane