1

I have a text file which contains the following lines:

7.3.0
12

I am using the below lines to read the content line by line

while read -r LINE; do
    if test $n -eq 1 
    then 
       var01=$LINE
    fi
    if test $n -eq 2 
    then 
       var02=$LINE
    fi
    n=`expr $n + 1`
done < <(tr -d '\r' < /mnt/Share/hpsum_build.txt)

the above code doesn't read 2nd line that is last line '12' which doesn't end with a new line. How to read the last line as well

1 Answer 1

2

If your text line doesn't have an ending newline then you can do this at start of your script to force a newline in it:

echo '' >> /mnt/Share/hpsum_build.txt

You can also call dos2unix utility to remove DOS's \r before \n from each line.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.