|
|
|
|
||||||
| linux.debian.user debian-user@lists.debian.org. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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----- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
>
> 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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----- |
|
![]() |
| Outils de la discussion | |
|
|