sed awk 小例
实现数据库批量更新与回滚
create database awktest;
use awktest
create table user(
id int unsigned not null unique auto_increment primary key,
name varchar(40) not null,
value int unsigned not null
)ENGINE=InnoDB DEFAULT CHARSET=utf8 comment='user表';
insert into user(id, name, value) values ('1','xiao1','18'),
('2','xiao2','19'),
('3','xiao3','20'),
('4','xiao4','21');
exit
mysql -uroot -p -e 'use awktest;select * from user;' > datadump.txt
nl datadump.txt | sed '1d' | awk -F ' ' '{printf ("update user set value = 0 where name = \047%s\047;\n", $3)}' > sql.txt
nl datadump.txt | sed '1d' | awk -F ' ' '{printf ("update user set value = %s where name = \047%s\047;\n",$4,$3)}' > rollback.txt
db -Dawktest < ~/sql.txt
db -Dawktest < ~/rollback.txt
其中sql.txt:
update user set value = 0 where name = 'xiao1';
update user set value = 0 where name = 'xiao2';
update user set value = 0 where name = 'xiao3';
update user set value = 0 where name = 'xiao4';
rollback.txt:
update user set value = 18 where name = 'xiao1';
update user set value = 19 where name = 'xiao2';
update user set value = 20 where name = 'xiao3';
update user set value = 21 where name = 'xiao4';
sed awk 小例的更多相关文章
- sed awk 样例
sed [options] '[action]' filename options: -n:一般sed命令会把所有数据都输出到屏幕,如果加入此选项,则只会把经过sed命令处理的行输出到屏幕. -e:允 ...
- linux 命令小例
xargs示例: ls |xargs -i mv {} /opt find示例: find -mtime +n -name “*.avi” -type f -exec rm {} \; find - ...
- Sed&awk笔记之sed篇
http://blog.csdn.net/a81895898/article/details/8482387 Sed是什么 <sed and awk>一书中(1.2 A Stream Ed ...
- Sed&awk笔记之sed篇(转)
Sed是什么 <sed and awk>一书中(1.2 A Stream Editor)是这样解释的: Sed is a "non-interactive" strea ...
- Sed文本替换一例
使用 Sed 完成文本替换操作任务是非常合适的. 现在, 假设我要将一个原有 Java 项目中的一些包及下面的类移到另一个项目中复用. Project javastudy: Packages: alg ...
- [svc]linux正则实战(grep/sed/awk)
企业实战: 过滤ip 过滤出第二行的 192.168.2.11. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ine ...
- Linux三剑客grep/sed/awk
grep/sed/awk被称为linux的“三剑客” grep更适合单纯的查找或匹配文本: sed更适合编辑匹配到的文本: awk更适合格式化文本,对文本进行较复杂各式处理: Grep --color ...
- Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例
Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例 一.在Eclipse下编译安装Hadoop插件 Hadoop的Eclipse插件现在已经没有二进制版直接提供,只能自己编译. ...
- linux sed awk seq 正则使用 截取字符 之技巧
[root@room9pc01 ~]# seq 5 1 2 3 4 5 [root@room9pc01 ~]# seq 2 5 2 3 4 5 seq 1 2 10 1 3 5 7 9 [root@d ...
随机推荐
- magento寄存器的使用
1.Mage::register('validation_image_name', $validationImageName);//这个是把变量$validationImageName存储在valid ...
- 【Flash ANE iOS】关于Flash ANE在iOS上面遇到的一些问题
1.下载Flash Builder: https://www.adobe.com/support/downloads/detail.jsp?ftpID=5516 2.如何生成p12文件: http:/ ...
- hdu_5507_GT and strings(AC自动机)
题目链接:hdu_5507_GT and strings 题意:给n个字符串和q个询问,每个询问给两个数字x,y,问1.x是否为y的子序列,2.x是否为y的子串,是输出1,否则输出0,每个询问输出2个 ...
- poj_1743_Musical Theme(后缀数组)
题目链接:poj_1743_Musical Theme 题意: 给你一串数字,让你找最长的变化相同不重叠的子串,至少长度为5 题解: 处理数据后用后缀数组加二分答案,然后用height数组check答 ...
- 多尺度二维离散小波分解wavedec2
对X进行N尺度小波分解 [C,S]=wavedec2(X,N,'wname'); clc,clear all,close all; load woman; [c,s]=wavedec2(X,2,'db ...
- 异常处理try-catch-finally笔记
当程序发生异常时,我们期望:返回到一种安全状态,并能够让用户执行一些其他的命令:或者 允许用户保存所有操作的结果,并以适当的方式终止程序. 异常处理机制:程序的执行过程中如果出现异常,会自动生成一个异 ...
- Gentoo安装详解(五)-- 安装X桌面环境
安装X桌面环境: 安装Xorg: 检测显卡信息: dmesg | grep video lspci | grep -i VGA 配置INPUT_DEVICE.VIDEO_CARDS变量: 在安装Xor ...
- 多线程---其他方法 停止线程、守护线程、join方法
第三方停止线程: 原来是stop(),因为该方法有些问题,所以被interrupt()方法取代,它的用途跟机制是 当没有指定的方式让冻结的线程恢复到运行状态时,这时需要对冻结进行清除,强制让线程恢复到 ...
- Swift-HELP
//获取网页地址对应的字符串 var urlString = url.absoluteURL.absoluteString
- 移动端touch触屏滑动事件、滑动触屏事件监听!
一.触摸事件 ontouchstart.ontouchmove.ontouchend.ontouchcancel 目前移动端浏览器均支持这4个触摸事件,包括IE.由于触屏也支持MouseEvent,因 ...