当前位置:网站首页>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);
边栏推荐
- FlutterWeb瀏覽器刷新後無法回退的解决方案
- Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
- Flink analysis (II): analysis of backpressure mechanism
- 05个人研发的产品及推广-数据同步工具
- Optimization of middle alignment of loading style of device player in easycvr electronic map
- Debug xv6
- 06 products and promotion developed by individuals - code statistical tools
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- 应用服务配置器(定时,数据库备份,文件备份,异地备份)
- 基于LNMP部署flask项目
猜你喜欢
Unity粒子特效系列-闪星星的宝箱
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
Grafana 9 正式发布,更易用,更酷炫了!
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
Uipath browser performs actions in the new tab
Integrated development management platform
EasyRE WriteUp
2022年大厂Android面试题汇总(一)(含答案)
Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
BearPi-HM_ Nano development board "flower protector" case
随机推荐
MySQL报错解决
Solr appears write Lock, solrexception: could not get leader props in the log
The problem of "syntax error" when uipath executes insert statement is solved
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
Reppoints: advanced order of deformable convolution
Quick start of Hongmeng system
How to submit data through post
【ASM】字节码操作 ClassWriter 类介绍与使用
Application service configurator (regular, database backup, file backup, remote backup)
Selenium test of automatic answer runs directly in the browser, just like real users.
Hongmeng introduction and development environment construction
CTF reverse entry question - dice
Uipath browser performs actions in the new tab
C#WinForm中的dataGridView滚动条定位
灵活报表v1.0(简单版)
Binary search strategy
Remote code execution penetration test - B module test
BearPi-HM_ Nano development board "flower protector" case
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system