0

hello i have below issue in the while loop , it is not reading last line .

  
  while IFS= read -r line
  do
       echo $line
  done<file_ref_col_master.txt

input file

FILE_ID~col_POS~COL_START_POS~COL_END_POS~datatype~delimitted_ind~col_format~columnlength
5~4~~~char~Y~\"[a-z]+@gmail.com\"~100
5~1~~~char~Y~[0-9]+~100

current output

sh -x  sample1.sh
+ dos2unix /test/data/infa_shared/dev/SrcFiles/datawarehouse/poc_anjali/file_ref_col_master.txt
dos2unix: converting file /test/data/infa_shared/dev/SrcFiles/datawarehouse/poc_anjali/file_ref_col_master.txt to Unix format ...
+ n=0
+ IFS=
+ read -r line
+ echo FILE_ID~col_POS~COL_START_POS~COL_END_POS~datatype~delimitted_ind~col_format~columnlength
FILE_ID~col_POS~COL_START_POS~COL_END_POS~datatype~delimitted_ind~col_format~columnlength
+ IFS=
+ read -r line
+ echo '5~4~~~char~Y~\"[a-z]+@gmail.com\"~100'
5~4~~~char~Y~\"[a-z]+@gmail.com\"~100
+ IFS=
+ read -r line

1 Answers1

2

The last line of the file doesn't end with a newline.

Fix that with

printf "\n" >>file_ref_col_master.txt
Chris Davies
  • 116,213
  • 16
  • 160
  • 287