1. 循环处理文件的每一行:
cat ./myfile | while read line ; do
if [[ ${line::1} == "#" ]]; then
continue
fi
# remove space and empty line
line=${line// /}
if [[ "$line" == "" ]] ;then
continue
fi
...
done
2. 字符串处理
2.1 删除左边的字符(#)
${var#*xx}
2.2 删除右边的字符(%)
${var%xx*}
2.3 删除左边的字符(尽量多匹配)(##)
${var##*xx}
2.4 删除右边的字符(尽量多匹配)(%%)
${var%%xx*}
2.5 按长度截取(从左开始)
${var:start:length} # length从start数
${var:start:-length} # length从最右数