While 循环问题(不读取最后一行)

While 循环问题(不读取最后一行)

你好,我在 while 循环中遇到以下问题,它没有读取最后一行。

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

输入文件

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

电流输出

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][email protected]\"~100'
5~4~~~char~Y~\"[a-z][email protected]\"~100
+ IFS=
+ read -r line

答案1

文件的最后一行不以换行符结尾。

解决这个问题

printf "\n" >>file_ref_col_master.txt

相关内容