下面是输入
This is shard24 and date 20170801
This is shard24 and date 20170801
This is shard25 and date 20180101
file | sed -e 's/.*\(2018[0-9]*\).*/\1/p' -e 's/.*\(shard[0-9]*\).*/\1/p'
上面的命令给我的价值是
shard24
20170801
shard24
20170801
shard25
20180101
预期产量
shard2420170801
shard2420170801
shard2520180101
答案 0 :(得分:0)
使用sed
个常规表达式
sed -e 's/.*\(shard[0-9]*\).*\(201[0-9]\+\).*/\1\2/'
或带有扩展的正则表达式
sed -re 's/.*(shard[0-9]*).*(201[0-9]+).*/\1\2/'
看起来更清晰