shell-06|shell-06 字符串类()

shell-06|shell-06 字符串类()
文章图片
image.png

1.tr 函数的使用:所有的小写字母变成大写 read answer answer=`echo $answer | tr [a-z] [A-Z]` 把answer中的内容读取出来传递给tr函数,tr函数把answer中所有的小写字母变成大写字母2.echo的使用:输出但是不换行 echo -n "Can you write device drivers?" 输出但是不换行3.使用cut选定字段 ls -l | cut -c 1-10选定每行前10个字符 cut -d : -f 1,5 /etc/passwd以:为界定符,选取passwd文件的第一个和第五个字段 NOTE:cut区分space和tab.默认的是tab4.tr命令的使用 语法如下:tr [options] source-char-list replace-char-list 示例:有一个test文件,内容为:aaabbbcccdddefghiii tr -c "a" "z" < test | cat得到结果:aaazzzzzzzzzzzzzzzzz,除了a以外,其它字符都用z替换 tr -d "ad" < test | cat得到结果:bbbcccefghiii,a和d字符被删除 tr -s "ad" < test | cat得到结果:abbbcccdefghiii,浓缩a和d字符为一个5.去回车,空格和空行: enter to space: 去掉回车 tr '\n' ' ' 去除所有空格: sed 's/ //g' 去除多个空格: sed -e 's/[[:space:]][[:space:]]*/ /g' 去除行首的空格: sed 's/^[ \t]*//' 把tab变成空格: sed 's/\t/ /g' filename 删除文件中的空行: sed /^$/d filename 删除内容为多个空格/tab组成的行: sed /^[[:space:]]*$/d filename6.确定一串字符的长度:AWK方法 echo "hsdfsdfds fdsf" | awk '{ printf ("%d",length($0)) }' EXECUTOR=ecefjma USER_RIGTHS_FILE=user_rights [root@xiwen-aly xiwen]# grep ecefjma user_rights ecefjma francisco.javier.mateos@ericsson.com ADMIN gawk '$1 == "'$EXECUTOR'" {print $3}' $USER_RIGTHS_FILE ADMIN7.关于expr从特定位置取特定长度字符问题: [root@localhost findcdr]# ms=`expr substr 123456 3 2` [root@localhost findcdr]# echo $ms 348.linux输出指定行 linux输出指定行 eg: 输出第10行。 sed -n "10,1p" filename显示整个文件:sed -n '1,$'p temp.txt$为最后一行9.Echo Format character and other advance usage. echo -n "Please, do "'\E[1; 33; 44m'"NOT"; tput sgr0 echo -e " book a eselnvmai 1xxx if you DO NOT NEED to run SAPC"; tput sgr010. Sedsed -i '/inset_bf_here/icontent_inserted' /etc/security/limits.conf[root@aly ~]# echo "qwert aaaaa" | sed 's/\([^ ]\+\).*$/\1/' qwert[root@aly ~]# echo " qwert aaaaa" | sed 's|\([^ ]\+\).*$|\1|' qwert\1 instead of change, it just display what is regulared. awk -F"=" '{ print $2 }' | awk -F" " '{ print $1 }' sed -i s"/^NAME/\/\/NAME/" /opt/telorb/axe/tsp/config/epct/E10Name.epct echo "NAME "TLM_HS47701_filter4Tra"; " >> /opt/telorb/axe/tsp/config/epct/E10Name.epct 7epct -vF -u /opt/telorb/axe/loadingGroup01_1/TSP6830_SAPC14B_LSV09.config /opt/telorb/axe/tsp/config/epct/E*.epct | tee /tmp/TLM_output 8echo $? 9echo -e "AD source: TSP6830_SAPC14B_LSV09\nconfig: TSP6830_SAPC14B_LSV09.config\nO_STP: $TSP_HOST" > /tmp/TLM_output_cut 10cat /tmp/TLM_output | grep -e "\*\*" -A 200 >> /tmp/TLM_output_cut 11cat /tmp/TLM_output_cut 12cat /tmp/TLM_output_cut | grep -v generating | grep -v copying > upgradePackages/TLM_HS47701_filter4Tra/info.txt 13cp -a upgradePackages/* /opt/telorb/axe/upgradePackages/ 14echo $? 15exit $ xedit /opt/mirror/tsp/ss7/cnf/signmgr.cnf & Properly set the "location" fields: export.location=/opt/mirror/tsp/ss7/cnf/ config.location=/opt/mirror/tsp/ss7/cnf/config/ template.location=/opt/mirror/tsp/ss7/cnf/templates/ import.location=/opt/mirror/tsp/ss7/cnf/ Comment out the "rio" fields: # Remote I/O parameters (used by Signalling Manager applet) # rio.host.name=platform-vip # rio.user.name=telorb # rio.protocol.type=sftp # rio.timeout=20000 Go to the Signaling Manager bin location: $ cd /opt/SignallingManager/bin/ Start the Signaling Manager GUI: $ ./signmgui &cd /opt/mirror/tsp/ss7/cnf/ cp signmgr.cnf signmgr.cnf.`date +%y%m%d` sed -i 's/^export.location=\(.*\)/export.location=\/opt\/mirror\/tsp\/ss7\/cnf\//' signmgr.cnf sed -i 's/^config.location=\(.*\)/config.location=\/opt\/mirror\/tsp\/ss7\/cnf\/config\//' signmgr.cnf sed -i 's/^template.location=\(.*\)/template.location=\/opt\/mirror\/tsp\/ss7\/cnf\/templates\//' signmgr.cnf sed -i 's/^import.location=\(.*\)/import.location=\/opt\/mirror\/tsp\/ss7\/cnf\//' signmgr.cnf sed -i '/^rio./s/^/#/' signmgr.cnf./signmgui &

云平台开发运维解决方案@george.sre
个人主页:https://geekgoogle.com
GitHub: https://github.com/george-sre
Mail: george.sre@hotmail.com
: georgesre -
【shell-06|shell-06 字符串类()】欢迎交流~

    推荐阅读