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
Reply to: