In apps, it's common that user changes setting of FTP client so that uploaded DOS plain text file contains a ^M at the end of each line. Such ^M usually cause wrong data in table after sqlldr loads it, sometimes shell script containing such ^M will also error out in concurrent program. After some googling, I hit a command named 'tr'.
#export file_name=test.txt
#tr -d "[/r]" < $file_name >$file_name.1
This removes ^M.
In my previous post Carrying filename and request_id into table when doing sqlldr, ^M causes wrong awk output. Since I need to append file_name,request_id at then end of each line. So I need to remove empty lines, which can also achieved by tr command, see follwonig command
#export file_name=test.txt
#tr -d "[/r]" < $file_name >$file_name.1
#tr -s "[/n]" < $file_name.1 >$file_name.2
#mv $file_name.2 $file_name
finally , append filename and request_id using follwong command.
#cat $file_name | awk -F, '{printf("%s/n",$0",'$v_req_id','$file_name'")}' > $file_name.dat
How to remove ^M in a uploaded text file?
最新推荐文章于 2024-01-11 09:45:07 发布
本文介绍了一种使用Unix/Linux下的tr命令来移除从DOS格式上传的纯文本文件中的^M字符的方法。这些^M字符通常会导致SQL*Loader加载数据时出现问题或者在shell脚本中并发执行时发生错误。

5546

被折叠的 条评论
为什么被折叠?



