sed删除包含日期的行

时间:2015-12-23 15:10:39

标签: bash sed

我有一个包含大量(3400多行)网址列表的文件,每个网址都是这样的:

http://examplesite/rn/index.php?PageID=SF01_02_01&ID=2015-12-23-0012

我想要做的是使用sed选择包含今天日期的所有行。

我一直在尝试的是:

datetoday=$(date +%Y-%m-%d)
sed "/$datetoday/!d" en.html

然而,这似乎使文件空白,表明没有行符合字符串。有什么建议吗?

2 个答案:

答案 0 :(得分:2)

您可以使用标记type Traversal s t a b = forall f. Applicative f => (a -> f b) -> (s -> f t) data TraversalR s t a b = TraversalR { toListOfR :: s -> [a], setListR :: [b] -> s -> t } newtype CL a b = CL { getCL :: [a] } -- ConstantList instance Functor (CL a) where fmap _ (CL xs) = CL xs instance Applicative (CL a) where pure _ = CL [] (CL xs) <*> (CL ys) = CL (xs ++ ys) collectBs :: State [b] b collectBs = state $ \xs -> case xs of [] -> error "Too few bs" (y:ys) -> (y,ys) travToTravR :: Traversal s t a b -> TraversalR s t a b travToTravR tr = TraversalR { toListOfR = getCL . tr (CL . pure), setListR = \bs s -> evalState (tr (const collectBs) s) bs } travRToTrav :: TraversalR s t a b -> Traversal s t a b travRToTrav trR a2fb s = (`setL` s) <$> f_bs where as = toListOfR trR s f_bs = sequenceA . map a2fb $ as setL = setListR trR 代替p

d

答案 1 :(得分:1)

您可以使用GNU awk而不是2个单独的命令:

awk '$0~strftime("%F")'