shell编程实战17

1. 问候用户

  

2. 格式化输出xml

#!/bin/bash

sed '/<!--.*-->/d' test.xml > test2.xml ## 注释符在一行的情况
egrep -n '<!--|\-\->' test2.xml |awk -F ':' '{print $1}' > /tmp/line_number1.txt
n=`wc -l /tmp/line_number1.txt|awk '{print $1}'`
n1=$[$n/2] ## 计算出注释符的对数
## 删除注释行
for i in `seq 1 $n1`
do
j=$[$i*2]
k=$[$j-1]
x=`sed -n "$k"p /tmp/line_number1.txt`
y=`sed -n "$j"p /tmp/line_number1.txt`
sed -i "$x,$y"d test2.xml
done

grep -n 'artifactItem>' test2.xml |awk '{print $1}' |sed 's/://' > /tmp/line_number2.txt
n2=`wc -l /tmp/line_number2.txt|awk '{print $1}'`

get_value(){
sed -n "$1,$2"p test2.xml|awk -F '<' '{print $2}'|awk -F '>' '{print $1,$2}' > /tmp/value.txt

cat /tmp/value.txt|while read line
do
x=`echo $line|awk '{print $1}'`
y=`echo $line|awk '{print $2}'`
echo artifactItem:$x:$y
done
}

n3=$[$n2/2]
for j in `seq 1 $n3`
do
m1=$[$j*2-1]
m2=$[$j*2]
nu1=`sed -n "$m1"p /tmp/line_number2.txt`
nu2=`sed -n "$m2"p /tmp/line_number2.txt`
nu3=$[$nu1+1]
nu4=$[$nu2-1]
get_value $nu3 $nu4
done

3. 小函数

 

4. 批量杀进程

 

5. 查找老日志并打包

 

6. 处理文本

 

猜你喜欢

转载自www.cnblogs.com/tanzhirong/p/11538058.html