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

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

Attachment: signature.asc
Description: Digital signature


Reply to: