当前位置:网站首页>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);
边栏推荐
- Total / statistics function of MySQL
- 遠程代碼執行滲透測試——B模塊測試
- 当前系统缺少NTFS格式转换器(convert.exe)
- Display picture of DataGridView cell in C WinForm
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
- Concept and basic knowledge of network layering
- Virtual machine startup prompt probing EDD (edd=off to disable) error
- 网络分层概念及基本知识
- [ASM] introduction and use of bytecode operation classwriter class
- Summary of study notes for 2022 soft exam information security engineer preparation
猜你喜欢

【ASM】字节码操作 ClassWriter 类介绍与使用

05 personal R & D products and promotion - data synchronization tool

TCP连接不止用TCP协议沟通

node の SQLite

在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?

CTF reverse entry question - dice

Selenium test of automatic answer runs directly in the browser, just like real users.

Sqoop I have everything you want

Display picture of DataGridView cell in C WinForm

06 products and promotion developed by individuals - code statistical tools
随机推荐
03 products and promotion developed by individuals - plan service configurator v3.0
Quick start of Hongmeng system
【MySQL入门】第一话 · 初入“数据库”大陆
Vscode matches and replaces the brackets
Summary of study notes for 2022 soft exam information security engineer preparation
Remote code execution penetration test - B module test
Kernel link script parsing
Precipitated database operation class - version C (SQL Server)
[ASM] introduction and use of bytecode operation classwriter class
The most complete tcpdump and Wireshark packet capturing practice in the whole network
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
C# NanoFramework 点灯和按键 之 ESP32
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
mysql高级(索引,视图,存储过程,函数,修改密码)
PyTorch 提取中间层特征?
The problem of "syntax error" when uipath executes insert statement is solved
Spark accumulator and broadcast variables and beginners of sparksql
Summary of Android interview questions of Dachang in 2022 (II) (including answers)