Search code examples
sedbsd

Sed remove matching lines script


I'm requesting help with a very simple script...

#!/usr/bin/sed -f

sed '/11,yahoo/d'
sed '/2506,stackover flow/d'
sed '/2536,reddit/d'

Just need it to remove three matches that account for 18408 in my file, data.csv

% sed -f remove.sed < data.csv 
sed: 3: remove.sed: unterminated substitute pattern

Doing these same lines individually is no problem at all, so what am I doing wrong with this?

Using freeBSD 10.1 and its implementation of sed, if that matters.


Solution

  • This, being a sed script, should not have "sed" at each line.

    Either change it to:

    #!/usr/bin/sed -f
    
    /11,yahoo/d
    /2506,stackover flow/d
    /2536,reddit/d
    

    Or to

    #!/bin/sh
    
    sed -e /11,yahoo/d \
    -e /2506,stackover flow/d \
    -e /2536,reddit/d