[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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


Reply to: