您的位置:首页 > 其它

How to remove ^M in a uploaded text file?

2008-01-25 17:25 435 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: