一、将以下字符串
fat110
abcca
fat136
bcdfg
fat123
hell0
fat122
world1
转为如下形式
fat110=abcca
fat136=bcdfg
fat123=hell0
fat122=world1
方法如下:
[root@iZ23hh6yk41Z test]# cat test.txt |xargs -n 2|tr ' ' '='
[root@iZ23hh6yk41Z test]# cat test.txt |xargs -n 2|awk 'BEGIN{RS=" ";ORS="="}{print}'
[root@iZ23hh6yk41Z test]# sed 'N;s#\n#=#g' test.txt
[root@iZ23hh6yk41Z test]# while read line;do if [ $(echo $line|grep fat|wc -l) -ne 1 ];then echo =$line;else echo -n $line;fi;done < test.txt
二、将下面内容
1#12@3#2837854155@4#1720@6#18452461013@7#1419923604
取出 # 号后面的数字做求和运算,也就是计算 12+2837854155+1720+18452461013+1419923604
[root@linux-node ~]# cat test.txt
1#12@3#2837854155@4#1720@6#18452461013@7#1419923604
[root@linux-node ~]#
[root@linux-node ~]# grep -oP '(?<=#)\w+' test.txt
12
2837854155
1720
18452461013
1419923604
[root@linux-node ~]# grep -oP '(?<=#)\w+' test.txt | awk '{sum+=$1} END {print sum}'
22710240504