当前位置:网站首页>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);
边栏推荐
- The art of Engineering (3): do not rely on each other between functions of code robustness
- About selenium starting Chrome browser flash back
- Unity particle special effects series - treasure chest of shining stars
- Kali2021 installation and basic configuration
- Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
- CTF reverse entry question - dice
- Openharmony developer documentation open source project
- Wechat applet obtains mobile number
- [rapid environment construction] openharmony 10 minute tutorial (cub pie)
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
猜你喜欢
2022年大厂Android面试题汇总(一)(含答案)
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
Flink parsing (III): memory management
Final review of information and network security (full version)
EasyCVR授权到期页面无法登录,该如何解决?
[introduction to MySQL] third, common data types in MySQL
About selenium starting Chrome browser flash back
Vscode replaces commas, or specific characters with newlines
03个人研发的产品及推广-计划服务配置器V3.0
OpenCV中如何使用滚动条动态调整参数
随机推荐
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
面试突击63:MySQL 中如何去重?
About selenium starting Chrome browser flash back
The art of Engineering
Vscode replaces commas, or specific characters with newlines
FlutterWeb浏览器刷新后无法回退的解决方案
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Final review of information and network security (based on the key points given by the teacher)
自动化运维利器-Ansible-Playbook
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
【ASM】字节码操作 ClassWriter 类介绍与使用
The art of Engineering (3): do not rely on each other between functions of code robustness
02个人研发的产品及推广-短信平台
Huawei certified cloud computing hica
Guidelines for preparing for the 2022 soft exam information security engineer exam
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
分布式不来点网关都说不过去