Re: sed command spanning multiple lines



Russell L. Harris schrieb:
Is it possible to spread a sed command over multiple lines, to improve
readability (for the sake of future maintenance)? If so, what
character is used to break the line and what are the rules?

For example, I would like to re-write the command:

sed -e 's/\.//g' -e 's/\,//g' -e 's/\\//g' "$1" | sort -u > foo

as:

sed -e 's/\.//g'
-e 's/\,//g'
-e 's/\\//g' "$1"
| sort -u > foo

and be able to add additional lines such as:

-e 's/[0-9]//g'



Hello,

sure you can, just as any other command between the arguments, but not
between.
The command lines are interpreted by the shell, not by the programs,
they just get the arguments they were called with as an ordered data
package, but don't usually have anything to do with the way they were
called.
You may escape a linebreak just as any other charater in all Linux/Unix
shells I know, just remember that the <Enter> must come immediately
after the backspace:

sed -e 's/\.//g' \
-e 's/\,//g' \
-e 's/\\//g' "$1" \
| sort -u > foo

Greetings,
Björn

Attachment: signature.asc
Description: OpenPGP digital signature



Relevant Pages

  • Re: zsh: how to make a function fail?
    ... foo { ... the command terminates normally without setting $?. ... Causes a shell function or. ... If return was executed from a trap in a TRAPNAL function, ...
    (comp.unix.shell)
  • Re: Handling of shell builtins in make(1)
    ... > I think I found a problem in the shell code in make, ... > command lines of a target are executed by one shell per line (this is ... > predefined set of shell builtins, ...
    (freebsd-arch)
  • Re: Handling of shell builtins in make(1)
    ... SL>> I think I found a problem in the shell code in make, ... SL>> is not called with -j) the command ... SL>> builtins, make directly exec's the command instead of using an intermediate ... SL>> foo: ...
    (freebsd-arch)
  • Handling of shell builtins in make(1)
    ... I think I found a problem in the shell code in make, ... command lines of a target are executed by one shell per line (this is also ... The problem is that the current list of builtins is ...
    (freebsd-arch)
  • [ANN] main-2.6.0
    ... a class factory and dsl for generating command line programs real ... option 'foo' ... improved auto usage generation when arity is used with arguments ... cast:int ...
    (comp.lang.ruby)