shell 中 循环 空格 空行 字符串转数值
? shell ?    2019-01-11 17:34:45    686    0    0
gua_l   ? shell ?

 

处理 行首空格 行尾空格 空行

去行首的空格/双引号

 sed 's/^[ \t]*//g'​
 sed 's/^"*//g'​

去掉行尾的空格/双引号

sed 's/[ \t]*$//g'
sed 's/"*$//g'​​

去掉空行

grep -v "^$"


 


循环之美

文件中每行是单个字符串:

transation_list=`cat ${USER}.transation_ID.record.txt`
for i in ${transation_list}
do
    echo ${i}
done​

文件中每行是几个字符串组:

cat ${USER}.${i}.file_list.txt | while read line
do
    echo ${line}  >> ${USER}_detail_info.txt
    FILE=`echo ${line}| cut -d " " -f 1`
    VERSION=`echo ${line}| cut -d " " -f 2`
    echo FILE is ${FILE} >> ${USER}_detail_info.txt
    echo VERSION is ${VERSION} >> ${USER}_detail_info.txt
done​

字符串转数字运算:

lines_total_=`cat ${USER}.${i}.lines.txt `
lines_total_all=`expr $lines_total_all + $lines_total_`​

 


 

 

Pre: Linux (Centos/redhat) 调整磁盘分区大小

Next: Accurev - 概述和常用操作/常用命令

686
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content