1, in three ways to achieve delete the last line of the file.
[[email protected] sjx]# cat 123123[[email protected] sjx]# sed ' $d ' 12312[[email protected] sjx]# cat 123 |head-$[$ (cat 123|WC-L) -1]12[[email protected] sjx]# cat 123 |sed-n ' $!p ' 12
2, using three ways to achieve the matrix of generating 3*3.
[[email protected] sjx]# for ((y=0;y<3;y++));d O for ((i=0;i<3;i++));d o echo-n "*";d one; echo;d one* * * * * * * * * [[email protected] sjx]# seq 3 |awk ' {for (i=1;i<=3;i++) {printf "%s", "*"}{printf "\ n"}} ' * * * * * * * * * * [[Email PR Otected] sjx]# awk ' begin{for (i=1;i<=3;i++) {for (y=1;y<=3;y++) {printf "%s", "*"}{printf "\ n"}}} ' * * * * * * * * * *
3, the use of three ways to achieve the IP address.
[[email protected] sjx]# ifconfig |grep ' inet addr ' |sed ' s/://' |awk ' {print $} ' 10.12.29.253127.0.0.1[[email protected] sjx]# ifconfig |grep ' inet addr ' |grep-o ' \<[[:d igit:]].*[[:d igit:]]\> ' | awk ' {print $} ' 10.12.29.253127.0.0.1[[email protected] sjx]# IP addr show |grep ' \<inet\> ' |sed ' s/\///' |awk ' {PR int $ A} ' 127.0.0.110.12.29.253
4, Seq 10 and then no three a line comma-delimited agreed to, in three ways to achieve, the results are similar:
The
3,4,5
5,6,7
7,8,9
9,10
[[email protected] sjx]# for ((i=1;i<10;i+=2));d o seq |sed-n ' $i ', +2p ' |xargs |sed ' s//,/g ';d one1,2,33,4,55,6,77,8 , 99,10[[email protected] sjx]# for ((i=1;i<10;i+=2));d o seq |sed-n ' $i ', +2p ' |awk ' {printf "%s", $1}end{printf "\ n" } ' |sed ' s//,/g ';d one |sed ' $s/,$//' 1,2,3,3,4,5,5,6,7,7,8,9,9,10[[email protected] sjx]# seq 10 | Xargs |awk ' {for (i=1;i<10;i+=2) {printf "%s,%s,%s\n", $i, $ (i+1), $ (i+2)}} ' |sed ' $s/,$//' 1,2,33,4,55,6,77,8,99,10
5. Using awk to print the hollow triangle, the results are similar to the following:
*
**
* *
* *
* *
* *
* *
* *
* *
**********
[[email protected] sjx]# awk ' begin{{printf "%s\n", "*"}for (i=1;i<10;i++) {{printf "%s", "*"}for (y=1;y<=i;y++) if ( Y<i) {printf "%s", "}else{printf"%s\n "," * "}}{for (z=1;z<=12;z++) if (z<12) {printf"%s "," * "}{printf" \ n "}} ' * *** ** ** ** ** ** ** ** ************
6, in three ways ECHO-E ' 123 123\naaa BBB ' The output results formatted as follows:
123 123
AAA BBB
[[email protected] sjx]# echo-e ' 123 123\naaa BBB ' |awk ' {print $1,$2} ' 123 123aaa Bbb[[email protected] sjx]# EC HO-E ' 123 123\naaa BBB ' |awk ' {printf '%s%s\n ', $1,$2} ' 123 123aaa Bbb[[email protected] sjx]# echo-e ' 123 123\n AAA BBB ' | Sed ' s/[[:space:]][[:space:]]\+//g ' 123 123aaa bbb[[email protected] sjx]# echo-e ' 123 123\naaa BBB ' | Sed ' s/[^[:alnum:]][^[:alnum:]]\+//g ' 123 123aaa BBB
Shell command Exercise 20160425