Sed remove matching lines script

青春壹個敷衍的年華 提交于 2019-12-11 12:33:52

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/30022558/sed-remove-matching-lines-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!