Shell 要点记录

来源:互联网 发布:aws centos 编辑:程序博客网 时间:2024/06/18 14:19

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从最右数


原创粉丝点击