How to convert dos2unix csv file with python script
NickName:prashant chhetri Ask DateTime:2019-10-13T19:25:46

How to convert dos2unix csv file with python script

I want to convert a csv file into dos2unix format using python in windows. Rightnow I am doing manually by placing csv file in workarea(server) and run command in putty.[Command : dos2unix file_received filename]

Copyright Notice:Content Author:「prashant chhetri」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58363093/how-to-convert-dos2unix-csv-file-with-python-script

Answers
RightmireM 2019-10-13T11:43:45

dos2unix (as I recall) pretty much only strips the trailing linefeeds off each line. So, there's two ways you can do this. \n\nwith open(filename, \"w\") as fout: \n with open(file_received, \"r\") as fin:\n for line in fin:\n line = line.replace('\\r\\n', '\\n')\n fout.write(line)\n\n\nor you can use subprocess to call the UNIX command directly. WARNING: This is bad since you're using a parameter file_received, and people could potentially tag executable commands into it. \n\nimport subprocess\nsubprocess.call([ 'dos2unix', file_received, filename, shell=False])\n\n\nI haven't tested the above. The shell=False (the default) means a UNIX shell won't be called for the process. This is good to avoid someone inserting commands into the parameters, but you may have to have shell=True in order for the command to work right. ",


More about “How to convert dos2unix csv file with python script” related questions

How to convert dos2unix csv file with python script

I want to convert a csv file into dos2unix format using python in windows. Rightnow I am doing manually by placing csv file in workarea(server) and run command in putty.[Command : dos2unix file_re...

Show Detail

shell script to convert windows file to unix using dos2unix

I'm writing a simple shell script to make use of dos2unix command to convert Windows-format files to Unix format as and when it arrives in my folder. I used to use iconv in the script and automate...

Show Detail

How to use dos2unix?

I am learning perl programming. I have run a perl script in windows platform but I need to run it in Linux platform like in Ubuntu. My script run perfectly in windows but not in Linux. I am not fam...

Show Detail

Difference dos2Unix and python script

I have files to convert to Unix format. What would be the differences/issues that I could face choosing python conversion way : import sys filename = sys.argv[1] text = open(filename, 'rb').read().

Show Detail

need to convert html to csv file using python or shell script

I have a html file and i need to convert this large html file into csv file and then load this csv file into mysql file can anyone suggest shell/python script to achive this task

Show Detail

Python script dow download JSON data and save as/convert to CSV

I am having trouble downloading data in a JSON format and converting it to a csv-file. In this case it is company overview data from alphavantage(https://www.alphavantage.co/query?function=OVERVIEW...

Show Detail

Convert txt to csv python script

I have a .txt file with this inside - 2.9,Gardena CA What I'm trying to do is convert that text into a .csv (table) using a python script: import csv import itertools with open('log.txt', 'r') as

Show Detail

how to convert Csv file to libsvm using python and pandas?

I had one csv file and i needed to convert it to libsvm format so i wrote a python script to make the required changes . Now the matrix i have in python is in the libsvm form but how to write it to

Show Detail

dos2unix: Binary symbol found, skipping binary file

I am currently having an issue where my script is failing when trying to execute the dos2unix command on a file. This is what I have in the script: dos2unix -n data/file data/tmp_file dos2unix: B...

Show Detail

Convert .csv file into .dbf using Python?

How can I convert a .csv file into .dbf file using a python script? I found this piece of code online but I'm not certain how reliable it is. Are there any modules out there that have this function...

Show Detail