How to remove ^M in a uploaded text file?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值