Linux shell按行读取文件


按行读取文件

#!/usr/bin/bash

# 当前目录
PWD=`pwd`

FILE="$PWD/itaken.txt"


i=0
# 读取每一行
while read LINE; do
    i=$((i+1))

    # 如果为空,则忽略
    if [[ "$i" == "" ]]; then
        continue
    fi

    echo "当前行内容: $i => $LINE"
done < "$FILE"

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录