我想转换:
Charlie answered 9 years ago
random text
Kevin answered 4 months ago
对此:
Charlie answered around March 2006
random text
Kevin answered around November 2014
使用以下代码:
date "+%B %Y" --date="9 years ago"
是我从获得的地方。
我是否应该使用for循环,因为我将使用实例,其中将有10个以上的日期表示“在______之前答复”
推荐哪个程序? Sed,awk,还有吗?
谢谢您,我正在为一位希望对Yahoo Answers的准确性进行研究的教授而做,非常感谢您的帮助。
最佳答案
用BASH进行:
while read -r line; do
[[ $line != *answered* ]] && echo "$line" && continue
date "+${line/answered */answered} around %B %Y" -d "${line#* answered }"
done < file
输出:
Charlie answered around March 2006
random text
Kevin answered around November 2014