$ cat foo.sh #!/bin/bash --norc cat infile | grep -v "^[[:space:]]*$" | # 空行をSKIP grep -v "^[[:space:]]*#" | # #で始まる行をSKIP while read LINE do LINE=`echo ${LINE} |sed 's/[[:space:]]*#.*//g'` # #以降はコメント扱い echo ":${LINE}:" done exit 0 $ $ cat infile ## comment line1 #1 line2 #2 line3 #3 line4#4 line5 #5 # comment # comment # comment $ $ ./foo.sh :line1: :line2: :line3: :line4: :line5: $