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-06-27 10:37:12 发布