Feed on
Posts
Comments

to spread a one-line command over multiple lines in a shell script, end each line with a slash and indent the next line.  for instance:

cat $1 | sed ‘s/>FALF/F_FAL/g’  \
| sed ‘s/>FAL1/1_FAL/g’  \
| sed ‘s/>FAL5/5_FAL/g’  \
| sed ‘s/>FALZ/Z_FAL/g’  \
| sed ‘s/>OUTGROUP/5_OUTGROUP/’ > $2


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

One Response to “spread a one-line command over multiple lines”

  1. on 01 Oct 2007 at 2:18 pm Eric Brunson

    That’s a good tip, but the example you used (sed) can be better written as:

    sed “s/>FALF/F_FAL/g
    s/>FAL1/1_FAL/g
    s/>FAL5/5_FAL/g
    s/>FALZ/Z_FAL/g
    s/>OUTGROUP/5_OUTGROUP/” $1 > $2

    Saves five processes. This doesn’t change your original meaning that you can spread multiple commands over several lines, but sed can take multiple directives in a single program.

    :-)

Did I get this wrong? Let me know!

Trackback URI | Comments RSS