从给定文件中读取第二列时
使用awk从给定文件读取多列时遇到问题。
读取第2列时,内容向右移动。

/home/Binay/bin] 82#head -2 /data/xyz/serial/fep_xyz/temp/./xyz_reject_file_details_20180926194730.dat
309_body_mass_index_at_refresh.ABORT.2018-05-13.dat_SKIP_AT|Failed MBR_KEY Lookup|94
309_disease_management_member_activity_at_refresh.ABORT.2018-05-13.dat_SKIP_AT|Failed MBR_KEY Lookup|11575
/home/Binay/bin] 82#

预期输出
/home/Binay/bin] 82#  cat /data/xyz/serial/fep_xyz/temp/./xyz_reject_file_details_20180926194730.dat | awk -F'|' ' {print $1,$2,$3} ' | while read abort_file abort_reason record_count                        <
> do
> echo ${abort_reason}
> done
Failed MBR_KEY Lookup
Failed MBR_KEY Lookup
/home/Binay/bin] 83#

但我目前得到的输出为
/home/Binay/bin] 82#  cat /data/xyz/serial/fep_xyz/temp/./xyz_reject_file_details_20180926194730.dat | awk -F'|' ' {print $1,$2,$3} ' | while read abort_file abort_reason record_count                        <
> do
> echo ${abort_reason}
> done
Failed
Failed
/home/Binay/bin] 83#

最佳答案

while IFS='|' read -r abort_file abort_reason record_count; do echo ${abort_reason}; done < filename

为什么不在while中直接使用输入字段分隔符?

08-28 10:51