I have almost 1GB csv file and need to edit that file with using regex and have to do find and replace on sublime with regex \=\\\" for finding and =' for replacing.

I can do it from spiting csv file but that is time taking process. If any one have idea to do this using sublime or VIM or any other way then that will be help for me. Thanks in advance.

  • I'd use a perl oneliner like perl -ane 's/="/=\'/g;print' inputfile > outputfile – Toto Jan 23 '18 at 15:52
  • Have you ever considered put all this data into a database you can just run queries against? – cybernard Jan 24 '18 at 4:06

Ok I got one solution for this using python code, which works successfully for me.

# import the modules that we need. (re is for regex)
import os, re

# set the working directory for a shortcut

# open the source file and read it
fh = file('file.csv', 'r')
thetext = fh.read()

# create the pattern object. Note the "r". In case you're unfamiliar 
with Python
# this is to set the string as raw so we don't have to escape our 
escape characters

#match all the character you want to replace like below
p1 = re.compile(r'\=\\\"')

# do the replace
result = p1.sub("='", result)

# write the file
f_out = file('newfile.csv', 'w')

and save it to yourfilename.py

and for ubuntu user open terminal and go to your file directory and run the command like

python ./yourfilename.py

this will replace =" to ='. Hope this will help ful to others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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