shell 提取json文件关键字

本文介绍了一个Shell脚本,该脚本用于从指定的JSON文件中读取并提取versionCode字段的值。通过正则表达式匹配,脚本能够准确地找到并输出所需的版本代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[
  {
    "outputType": {
      "type": "APK"
    },
    "apkData": {
      "type": "MAIN",
      "splits": [],
      "versionCode": 2019101910,
      "versionName": "6.2.0_beta1",
      "enabled": true,
      "outputFile": "app-development-debug.apk",
      "fullName": "developmentDebug",
      "baseName": "development-debug"
    },
    "path": "app-development-debug.apk",
    "properties": {}
  }
]

以上是JSON 文件的内容

#!/bin/sh

jsonpath='/root/test/output1.json'
appcode=''
if [ ! -f $jsonpath ]; 
  then echo "file not exist"
  exit 0
fi
while read line
do  
   #contain keywords
  [[ $line =~ "versionCode"  ]] && {
  
    appcode=${line:15:10}          
    echo $appcode
  } 
done < $jsonpath

if [ ! -n :"$appcode" ]; then
  # empty 
  exit 0
fi


echo $appcode

以上是脚本

可以使用PDFMiner这个Python库来提取PDF文件中的文本内容及其坐标信息。具体步骤如下: 1. 安装PDFMiner库,可以使用pip命令安装:`pip install pdfminer` 2. 编写Python脚本,使用PDFMiner库提取PDF文件中的文本内容及其坐标信息,例如: ``` import pdfminer.high_level as pdf def extract_text_with_coordinates(pdf_file): text_with_coordinates = [] for page_layout in pdf.extract_pages(pdf_file): for element in page_layout: if isinstance(element, pdfminer.layout.LTTextBoxHorizontal): for text_line in element: text_with_coordinates.append((text_line.get_text(), (text_line.x0, text_line.y0, text_line.x1, text_line.y1))) return text_with_coordinates pdf_file = open('example.pdf', 'rb') text_with_coordinates = extract_text_with_coordinates(pdf_file) pdf_file.close() print(text_with_coordinates) ``` 其中,`extract_text_with_coordinates`函数用于提取PDF文件中的文本内容及其坐标信息,返回一个列表,每个元素包含文本内容及其坐标信息。`pdf_file`为文件对象,需要使用rb模式打开。 3. 使用PHP调用Python脚本,获取文本内容及其坐标信息,例如: ``` $output = shell_exec("python extract_text_with_coordinates.py example.pdf"); $text_with_coordinates = json_decode($output); ``` 其中,`shell_exec`函数用于执行Python脚本,`json_decode`函数用于解析Python脚本输出的JSON格式数据。 需要注意的是,使用Python库需要安装Python环境,因此在PHP中调用Python脚本需要确保Python环境已经安装并配置好环境变量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值