1.打印99乘法表
-
awk 'BEGIN{for(n=1;n<=9;n++){for(i=1;i<=n;i++)printf i"x"n"="i*n" ";print}}'
2.打印最大的一行
a 100
a 101
a1 100
b 102
c 100
b 110
c1 110
a 210
要求:第一列里每个相同字符的第二列的最大值
-
sort -k2,2nr urfile | awk '!a[$1]++'
-
或者
-
awk 'a[$1]<$2{a[$1]=$2}END{for(i in a)print i,a[i]}' file
3.
13338695867苏州关注类点击手机摩托罗拉motox(x+1)(XT1085)
13338697913苏州关注类点击手机华为P8ALE-CL00
要求:在号码后面加入逗号
-
sed 's/.\{11\}/&,/1' file #1假如逗号的次数
4.
-
文本
-
"abc","abc","abc","abc","abc"
-
"abc","abc","abc
-
","abc","abc"
-
"abc","abc","abc","abc","abc"
-
"abc","abc","abc","abc","abc"
-
"abc","abc","abc","abc","abc"
-
"abc","abc","abc","abc","abc"
-
-
awk -F, 'NF==5{print}NF!=5{getline a;print $0""a}' file.txt
5.
-
要求是把文件中所有137,139等等开头的11位手机号码,中间几位替换成*号
-
如137******42
-
-
echo "13512507633"|sed '/^135\|137\|139......../s/\(...\).*\(..\)/\1\*\*\*\*\*\*\2/'
6.
-
按照列拆分文件
-
cat 1.txt
-
A B C D E
-
F G H I J
-
K L M N O
-
P Q R S T
-
U V W X Y
-
-
awk '{print $1 > "1.txt" ;print $2 > "2.txt"}' file
-
-
awk '{for(i=1;i<=NF;i++)print $i >i".txt"}' file
阅读(1975) | 评论(0) | 转发(0) |