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
#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 duplicate lines in a large text file?
- How to Open a Text File in VB .NET
- How to remove ^M in the file
- How to read Json file or text file in Spark
- How to read text file in client side via HTML5
- How to remove a line from a file in java?
- How To Enable or Disable Simple File Sharing in Windows XP
- Shell: how to list all db links in oracle DB to generate a flat file (生成dblink列表文件)
- How to remove an attribute in D3.js
- how to put the text on the left of a radio button in android
- git tip: How to undo an uncommitted change/deletion for a specific file in your working directory
- How to remove the component VOB in Components?
- How to Install a Bin File in Fedora
- How to generate file name according to datetime in bat command
- How do I convert from BLOB to TEXT in Mysql?
- How to re-create STM File in Exchange 2000/2003
- How To Trace The Remote File Server (RFS) Process In Physical Standby Database (Doc ID 1481125.1)
- How to remove administrative shares in Windows Server 2008 or 2012
- how to check unsolved conflicts file list in git merge?
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code