当前位置:网站首页>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);
边栏推荐
- 网络分层概念及基本知识
- BearPi-HM_ Nano development board "flower protector" case
- [ciscn 2021 South China]rsa writeup
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- 【MySQL入门】第三话 · MySQL中常见的数据类型
- 06 products and promotion developed by individuals - code statistical tools
- [rapid environment construction] openharmony 10 minute tutorial (cub pie)
- Re signal writeup
- 基于LNMP部署flask项目
- Solid principle
猜你喜欢
[translation] principle analysis of X Window Manager (I)
Vscode replaces commas, or specific characters with newlines
Huawei certified cloud computing hica
Unity粒子特效系列-闪星星的宝箱
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
pip install pyodbc : ERROR: Command errored out with exit status 1
Unity particle special effects series - treasure chest of shining stars
06个人研发的产品及推广-代码统计工具
应用服务配置器(定时,数据库备份,文件备份,异地备份)
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
随机推荐
[reverse intermediate] eager to try
Establishment of graphical monitoring grafana
RepPoints:可形变卷积的进阶
Compile and build, from the bottom to the top
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
Grafana 9 正式发布,更易用,更酷炫了!
Based on infragistics Document. Excel export table class
Selenium test of automatic answer runs directly in the browser, just like real users.
Total / statistics function of MySQL
基于LNMP部署flask项目
Binary search strategy
面试突击62:group by 有哪些注意事项?
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
Unity particle special effects series - treasure chest of shining stars
Detailed explanation of data types of MySQL columns
SAP UI5 框架的 manifest.json
PySpark算子处理空间数据全解析(4): 先说说空间运算
[reverse] repair IAT and close ASLR after shelling
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
Final review of information and network security (full version)