-1

this is a file without ^M at the end of each line:

$ cat -v test1
"Rec_Open_Date","MSISDN","IMEI","Data_Volume_Bytes","Device_Manufacturer","Device_Model","Product_Description"
"2015-10-06","427","060","137765","Samsung Korea","Samsung SM-G900I","$39 Plan"
"2015-10-06","592","620","0","Apple Inc","Apple iPhone 6 (A1586)","PREPAY  STD - TRIAL - #16"
"2015-10-06","007","290","0","Apple Inc","Apple iPhone 6 (A1586)","PREPAY PLUS - $0 -"
"2015-10-06","592","050","48836832","Apple Inc","Apple iPhone 5S (A1530)","Talk and Text Connect Flexi Plan"
"2015-10-06","409","720","113755347","Samsung Korea","Samsung SM-G360G","$29 CARRYOVER PLAN"
"2015-10-06","742","620","19840943","Apple Inc","Apple iPhone S (A1530)","PREPAY STD - $0 - #2"
"2015-10-06","387","180","0","HUAWEI Technologies Co Ltd","HUAWEI HUAWEI G526-L11","PREPAY STD - $1 - #4"
"2015-10-06","731","570","2258243","Samsung Korea","Samsung SM-N910U","Business Freedom"
"2015-10-06","556","910","13332272","Samsung Korea","Samsung GT-I9505","$49 Plan"

I would like to add ^Mat the end of every line.
I am looking at doing this in bash.How do I do this and what is the difference with ^M or with out?
Is it a windows v unix issue?

So this is what I want my output to look like:

"Rec_Open_Date","MSISDN","IMEI","Data_Volume_Bytes","Device_Manufacturer","Data_Volume_MB","Device_Model","Product_Description"^M
"2015-10-06","64220440427","352919063870060","137765","Samsung Korea","0.131383",137765,Samsung SM-G900I,"$39 Plan"^M
"2015-10-06","64211307592","352068069655620","0","Apple Inc","0",0,Apple iPhone 6 (A1586),"PREPAY  STD - TRIAL - #16"^M
3

2 Answers 2

1

You might consider using a tool like unix2dos or your favorite text editor of choice, eg vim:

vim +'set ff=dos|x' input_file

With sed you might be able to do something like:

sed -i 's/$/\r/' input_file
1
  • tks, sed -i solution works.
    – HattrickNZ
    May 11, 2016 at 21:07
1

If you don't have a tool such as unix2dos:

while IFS= read -r line; do printf '%s\r\n' "$line"; done <in >out

Not the answer you're looking for? Browse other questions tagged or ask your own question.