PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > linux.debian.user > sed command spanning multiple lines
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
linux.debian.user debian-user@lists.debian.org.

sed command spanning multiple lines

Réponse
 
LinkBack Outils de la discussion
Vieux 11/04/2007, 18h30   #1
Russell L. Harris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sed command spanning multiple lines

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'


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 11/04/2007, 18h40   #2
Björn Keil
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGHRwuY7BnBH/xFu8RAuwWAJ91BfM6DclF9xyrnkSJhchDyo20BgCePxif
97vD6HaZpUyNy+3L/DSH228=
=d8qG
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 11/04/2007, 18h50   #3
Cédric Lucantis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed command spanning multiple lines

Le mercredi 11 avril 2007 19:22, Russell L. Harris a écrit:
> 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'


bash simply accepts something like this:

sed /tmp/file -e '
s,h,,g
s,o,,g'

or you can put your commands in a separate file (one by line) and use -f
command-file instead of -e

in both cases, you can put several commands on the same line by separating
them with a ';'

--
Cédric Lucantis
  Réponse avec citation
Vieux 11/04/2007, 18h50   #4
Cédric Lucantis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed command spanning multiple lines

>
> sed -e 's/\.//g'
> -e 's/\,//g'
> -e 's/\\//g' "$1"


... but also note that this can be done with a single command (escaping is
useless here) : 's/[,/.]//g'

--
Cédric Lucantis
  Réponse avec citation
Vieux 11/04/2007, 19h50   #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
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h45.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10369 seconds with 13 queries