shell脚本实例-交叉证认
2016-02-25 17:05
639 查看
1、介绍
给一个老师写的交叉证认的脚本,人生中第一个脚本值得纪念一下。
2、功能
txt文件中某列数据格式为xxx1+xxx2,其中xxx1和xxx2均为数字,找出这个文件的行与行之间xxx1相等(也可以有其他关系)并且xxx2相等(同样可以有其他关系)的行并输出。
3、具体内容
里面都有注释,都是我一点一点敲上去的,因为虚拟机中没下输入法所以全是英文,仔细看看就能知道是什么。
4、运行步骤
a) chmod +x ./test.sh 使脚本具有执行权限
b) ./cross_match.sh 执行脚本
5、文件解释
运行脚本会产生一系列中间结果,为了处理方便,将他们都存入文档中
a) line2.txt 文本中所需要处理的列,此处为位置
b) line2_1.txt 所要处理列的前半部分,此处为赤经
c) line2_2.txt 所要处理列的后半部分,此处为赤纬
d) new.txt 将赤经赤纬插入为源文件的前两列
e) cross_match_1.txt 赤经符合要求的行
f) cross_match_1.txt 赤纬符合要求的行
6、 注意事项:每次使用脚本时需要更改所要处理的文件路径
PS:简直不能再爱自己了╮(╯▽╰)╭···哈哈哈···让我嘚瑟一下···
给一个老师写的交叉证认的脚本,人生中第一个脚本值得纪念一下。
2、功能
txt文件中某列数据格式为xxx1+xxx2,其中xxx1和xxx2均为数字,找出这个文件的行与行之间xxx1相等(也可以有其他关系)并且xxx2相等(同样可以有其他关系)的行并输出。
3、具体内容
#!/bin/bash echo "cross_match begin!" #cut the second line and save as "line2.txt" awk -F '\t' '{print $2}' /home/scidb/catalog/dr2_param.txt > line2.txt #replace "+" to "-" in line2 sed -i "s/+/-/g" line2.txt #cut the "line2.txt" line and save the first field as "line2_1.txt" cat line2.txt | cut -d '-' -f 1 > line2_1.txt #cut the "line2.txt" line and save the second field as "line2_1.txt" cat line2.txt | cut -d '-' -f 2 > line2_2.txt #paste line2_1 and line2_2 to the source file, and save as new.txt paste line2_1.txt line2_2.txt /home/scidb/catalog/dr2_param.txt > new.txt #find the same field_1 in the new.txt" gawk '{if(a[$1]=="") a[$1]=$0;else if(a[$1]!=""&&flag[$1]=="") {flag[$1]++;printf("%s\n%s\n", a[$1],$0);} else print $0}' new.txt > cross_match_1.txt #find the same field_2 in the new.txt" gawk '{if(a[$2]=="") a[$2]=$0;else if(a[$2]!=""&&flag[$2]=="") {flag[$2]++;printf("%s\n%s\n", a[$2],$0);} else print $0}' new.txt > cross_match_2.txt echo "cross_match end!"
里面都有注释,都是我一点一点敲上去的,因为虚拟机中没下输入法所以全是英文,仔细看看就能知道是什么。
4、运行步骤
a) chmod +x ./test.sh 使脚本具有执行权限
b) ./cross_match.sh 执行脚本
5、文件解释
运行脚本会产生一系列中间结果,为了处理方便,将他们都存入文档中
a) line2.txt 文本中所需要处理的列,此处为位置
b) line2_1.txt 所要处理列的前半部分,此处为赤经
c) line2_2.txt 所要处理列的后半部分,此处为赤纬
d) new.txt 将赤经赤纬插入为源文件的前两列
e) cross_match_1.txt 赤经符合要求的行
f) cross_match_1.txt 赤纬符合要求的行
6、 注意事项:每次使用脚本时需要更改所要处理的文件路径
PS:简直不能再爱自己了╮(╯▽╰)╭···哈哈哈···让我嘚瑟一下···
相关文章推荐
- shell获取 linux 系统的位数
- powershell 工作流作业
- linux中java调用shell脚本
- ansible模块command、shell、raw、script
- xshell里面使用黑色背景时蓝色字体看不清楚的解决方法
- shell printf命令:格式化输出语句
- shell 中数学计算总结
- 如何在shell脚本中判断文件或者文件夹是否存在?
- 如何在shell脚本中判断文件或者文件夹是否存在?
- 如何在shell脚本中判断文件或者文件夹是否存在?
- Powershell工作流中的function和script
- shell的if语句
- Shell命令行下如何查找并替换多个文件中的字符
- shell的for循环语句
- Shell的select语句
- shell中$( )与${ }及$(( ))的区别
- Powershell 工作流实战(1)
- shell 文本过滤器和SQL的比较
- 使用srcrpm包重新编译bash使之能够输出日志到rsyslog的local1
- Powershell工作流的限制