当前位置:网站首页>The shell generates JSON arrays and inserts them into the database
The shell generates JSON arrays and inserts them into the database
2022-07-06 17:44:00 【Oh, no, I forgot my paper】
Preface
Application scenarios : It needs to be used in actual projects shell Script to automatically insert part of the data in batch , and json Array is a commonly used data type .
** Now there is a batch of data about the floor room number, which needs to be in json Insert the array form into the database .**
The script content is attached directly below
Data presentation
[[email protected] ~]# cat floor.txt
1601
1612
1705
The script content
#!/bin/bash
floors=`cat floor.txt`
declare -a floor_info # Define an empty array
fid=1 # Definition fid
num=0 # Initialize array subscript
# Traverse the room numbers and add one to each room number key and value That is to say fid
for floor in $floors
do
floor_info[$num]={
\\\"fid\\\":\\\"$fid\\\",\\\"floor\\\":\\\"$floor\\\",\\\"url3d\\\":\\\"\\\"}
let fid++
let num++
done
floor_infos=`echo \\\[${
floor_info[*]}\\\] |sed 's/ /,/g'`
echo $floor_infos
Execute the script
[[email protected] ~]# . json.sh
\[{
\"fid\":\"1\",\"floor\":\"1601\",\"url3d\":\"\"},{
\"fid\":\"2\",\"floor\":\"1612\",\"url3d\":\"\"},{
\"fid\":\"3\",\"floor\":\"1705\",\"url3d\":\"\"}\]
[[email protected] ~]#
Before all special symbols \ Are used to identify special symbols , Otherwise, in the insert I will make a mistake
Remember in shell When inserting data in, you also need to add a single quotation mark before \
insert into floor (building_id,building_name,address,floor_info,floor_num,is_del) values(@projectid,'$building_name','$address',\'$floor_infos\',$floors_num,0);
边栏推荐
- PySpark算子处理空间数据全解析(4): 先说说空间运算
- 04个人研发的产品及推广-数据推送工具
- 07 personal R & D products and promotion - human resources information management system
- EasyRE WriteUp
- DataGridView scroll bar positioning in C WinForm
- Flink parsing (IV): recovery mechanism
- Solrcloud related commands
- 分布式不来点网关都说不过去
- Wechat applet obtains mobile number
- Summary of study notes for 2022 soft exam information security engineer preparation
猜你喜欢

Pytorch extract middle layer features?

Unity tips - draw aiming Center

学 SQL 必须了解的 10 个高级概念

Vscode replaces commas, or specific characters with newlines

Zen integration nails, bugs, needs, etc. are reminded by nails

基于STM32+华为云IOT设计的智能路灯

03 products and promotion developed by individuals - plan service configurator v3.0

自动化运维利器ansible基础

FlutterWeb浏览器刷新后无法回退的解决方案

04个人研发的产品及推广-数据推送工具
随机推荐
The NTFS format converter (convert.exe) is missing from the current system
面试突击63:MySQL 中如何去重?
自动化运维利器-Ansible-Playbook
Based on infragistics Document. Excel export table class
BearPi-HM_ Nano development environment
CTF reverse entry question - dice
Flink parsing (VII): time window
OpenCV中如何使用滚动条动态调整参数
Unity tips - draw aiming Center
Grafana 9 正式发布,更易用,更酷炫了!
虚拟机启动提示Probing EDD (edd=off to disable)错误
Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
The most complete tcpdump and Wireshark packet capturing practice in the whole network
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
connection reset by peer
Spark calculation operator and some small details in liunx
Spark accumulator and broadcast variables and beginners of sparksql
[reverse primary] Unique
05个人研发的产品及推广-数据同步工具
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)