gpt4 book ai didi

linux - 根据某些条件从文件中提取特定行(命令行)

转载 作者:太空宇宙 更新时间:2023-11-04 09:24:54 25 4
gpt4 key购买 nike

我在一个文件(实际上是一个巨大的文件)中有一些内容,如下所示,有什么方法可以提取行,其中lastAccessed值超过通过命令行确定值(比如 1464682814617)。

"url":"https://www.google.co.in/","title":"Google","lastAccessed":1464675219253,"hidden":false,""
"url":"https://www.google.com/intl/en/mail/help/about.html","title":"Gmail - Free Storage and Email from Google","persist":true,"lastAccessed":1464679910117,"hidden":false
"url":"https://www.facebook.com/","title":"Facebook - Log In or Sign Up","persist":true,"lastAccessed":1464682240507,"hidden":false
"url":"https://www.linkedin.com/","title":"World’s Largest Professional Network | LinkedIn","lastAccessed":1464682814617,"hidden":false,""
"url":"http://stackoverflow.com/","title":"Stack Overflow","persist":true,"lastAccessed":1464682191245,"hidden":false
"url":"http://www.indeed.co.in/?r=us","title":"Job Search India | one search. all jobs. Indeed","docIdentifier":5,"persist":true,"lastAccessed":1464674503732
"url":"https://www.google.com/intl/en/mail/help/about.html","title":"Gmail - Free Storage and Email from Google","persist":true,"lastAccessed":1464674739300,"hidden":false
"url":"http://stackoverflow.com/","title":"Stack Overflow","persist":true,"lastAccessed":1464674774653,"hidden":false

旁注:我正在处理节点应用程序。通过命令行做某事会更快或将其转换为 json obj 然后寻找正确的记录??


任何帮助/建议将不胜感激。提前致谢。

最佳答案

呆呆的:

 awk '{if ( gensub(/.*lastAccessed":([0-9]*).*/,"\\1","g",$0) > 1464682814617) {print}}' File

gensub 会提取字符串 "lastAccessed": 之后的数字,并与限制值进行比较,如果值大于限制值,则打印行。

如果 awksed 不可用:

while read line; do 
LASTA=$(echo "$line"| grep -o '"lastAccessed":[0-9]*' | cut -d: -f2) ;
if [ "$LASTA" -gt 1464682814617 ] ; then
echo $line
fi
done < File

关于linux - 根据某些条件从文件中提取特定行(命令行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37546854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com