bash - multiple sed commands: when semicolon, when pipeline? -


when construct complicated operation in sed, start with

cat infile | sed 'expression1' | sed 'expr2' ... 

and optimize into

cat infile | sed 'expr1;expr2;expr3' | sed 'expr4' | sed 'expr5;expr6' ... 

what guidelines there expressions can combined semicolons single command? far, ad hoc combine s///'s, , don't combine //d's.

(the optimization running tens of millions of times. yes, it's measurably faster.)

(posted here instead of on superuser.com, because has 20x fewer questions sed.)

better avoid multiple sed

sed -f mycmd.awk 

where mycmd.awk contain each sed command listed on separate line.

as per man sed:

-f command_file
append editing commands found in file command_file list of commands. editing commands should each listed on separate line.


Comments