[英]I want to extract specific text from txt or json file
i want to extract specific lines from bunch of text.我想从一堆文本中提取特定的行。 is there any way to extract all lines start with "text" and end at "}" from this file?
有没有办法从这个文件中提取所有以“text”开头并以“}”结尾的行? This is just a piece of code I have complete file..
这只是我拥有完整文件的一段代码..
"edge_media_to_caption": {
"edges": [
{
"node": {
"text": **"Summer is a state of mind.\n\n#locobeachresort #locoland #beachlife #batroun"**
}
}
]
},
"edge_media_to_caption": {
"edges": [
{
"node": {
"text": **"Sunshine is the best medicine.\n\n#locobeachresort #locoland #beachlife #batroun"**
}
}
]
},
If you're interested in python then如果您对 python 感兴趣,那么
lines = <your json>
for line in lines.split('\n'):
if 'text' in line:
<do whatever you want with the line>
selects these lines选择这些行
"text": **"Summer is a state of mind.
"text": **"Sunshine is the best medicine.
There is no walk-around for filtering specific lines from files.没有从文件中过滤特定行的方法。 You'd have to load the text in memory unless you have premature knowledge about the file's structure
您必须在 memory 中加载文本,除非您对文件结构有过早的了解
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.