Tuesday, December 28, 2010

Linux shell script loop to process files in a directory

To process .txt files in a directory, but skipping the first few and the last few -

count=0
ls | grep -E "\.txt" | while read line; do
    count=`expr $count + 1`
    if [ $count -le 10 ] ; then
        continue
    fi

    echo $line

    if [ $line = "xyz.txt" ]; then
        break
    fi
done

No comments:

Post a Comment