linux - | 中的字符串值awk 中分隔字段被拆分到右侧

标签 linux bash shell unix awk

从给定文件中读取第二列时 我在使用 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 中直接使用输入字段分隔符?

关于linux - | 中的字符串值awk 中分隔字段被拆分到右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52528986/

相关文章:

linux - 无法为新添加的 linux 用户设置密码

linux - (loopcount=loopcount+1) 和 ((loopcount=loopcount+1)) 有什么区别?

python - 如何让 python3 命令运行 Python 3.6 而不是 3.5?

python - 为什么 Python "preemptively"在尝试计算非常大的数字时会挂起?

linux - Samba 错误 : "Incorrect Function"

linux - 创建脚本以在 linux 中使用变量运行多个命令

bash:列出不具有给定扩展名的文件

linux - 无法再更新我的 Ubuntu 12.04 : python 2. 7 循环依赖项?

bash - Bash 中是否有 TRY CATCH 命令

bash - 在 bash 中连接字符串