public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] Short Question about sed
@ 2001-10-09  0:26 Sebastian Werner
  2001-10-09 11:39 ` Aron Griffis
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Werner @ 2001-10-09  0:26 UTC (permalink / raw
  To: Gentoo-Dev

Hey people,

i need a solution in a script to replace all backslashes (\). I know that i
how i replace slashes (/) (sed s/"\/"/"someelse"/g) but how i replace
backslashes.

Thank you for your help,

best regards,

Sebastian Werner

webmaster@parivital.org
http://www.paritaet-minden-luebbecke.de




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [gentoo-dev] Short Question about sed
  2001-10-09  0:26 [gentoo-dev] Short Question about sed Sebastian Werner
@ 2001-10-09 11:39 ` Aron Griffis
  0 siblings, 0 replies; 2+ messages in thread
From: Aron Griffis @ 2001-10-09 11:39 UTC (permalink / raw
  To: gentoo-dev

Sebastian Werner wrote:	[Tue Oct 09 2001, 01:27:53AM EST]
> i need a solution in a script to replace all backslashes (\). I know that i
> how i replace slashes (/) (sed s/"\/"/"someelse"/g) but how i replace
> backslashes.

sed 's/\\/replacement/'

Note that if you're replacing in a shell variable, you might consider
using the bash replacement syntax instead of calling out to sed.

Usage:

    VAR="${VAR#patt}"         # snip shortest match from front

    VAR="${VAR##path}"        # snip longest match from front

    VAR="${VAR%patt}"         # snip shortest match from end

    VAR="${VAR%%path}"        # snip longest match from end

    VAR="${VAR/patt/repl}"    # replace first occurance

    VAR="${VAR//patt/repl}"   # replace all occurances

    VAR="${VAR/#patt/repl}"   # replace, rooted to beginning (^ in regex)

    VAR="${VAR/%patt/repl}"   # replace, rooted to end ($ in regex)

Examples (not necessarily practical):

    progname="${0##*/}"       # snip entire path from program name

    newvar="${oldvar//\\\\/backslash}"  # note that \\\\ matches one backslash!

    set -- "${@/#/$D/}"       # prepend $D/ to all args

    newarray=("${@/#/$D}")    # same as last example, but put in newarray

Aron



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-10-09 17:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-09  0:26 [gentoo-dev] Short Question about sed Sebastian Werner
2001-10-09 11:39 ` Aron Griffis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox