Afficher un message
Vieux 11/04/2007, 20h50   #5
Andrew Sackville-West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed command spanning multiple lines

On Wed, Apr 11, 2007 at 12:22:16PM -0500, Russell L. Harris wrote:
> 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


use the escape character '\' before the carriage return on the lines
and I think it should work.

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

the \ escapes the return making the command appear as one line to
bash. make sure there are no other characters *after* the \

A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGHSL7aIeIEqwil4YRAoX3AKCRbCQgA78rDUVvPQR04D XuZjZeQgCgnIDl
FmruH5VvY2jN/+sKooTS3lA=
=TsZt
-----END PGP SIGNATURE-----

  Réponse avec citation
 
Page generated in 0,04915 seconds with 9 queries