Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8129361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:17:04+00:00 2026-06-06T08:17:04+00:00

I have to remove quotes from a relatively large text file. I have looked

  • 0

I have to remove quotes from a relatively large text file. I have looked at the questions that may have matched this one, yet I am still not able to remove the quotes from specific lines from the text file.

This is what a short segment from the file looks like:

1 - "C1".

E #1 - "C1".

2 - "C2".

1

2

E #2 - "C2".

I would like to have 1-"C1". be replaced by c1, and E #1 - "C1" be replaced with E c1. I tried replacing these in python, but I get an error because of the double "'s.

I tried:

input=open('file.text', 'r')
output=open(newfile.txt','w')
clean==input.read().replace("1 - "C1".","c1").replace("E #1 - "C1"."," E c1")
output.write(clean)

I have with sed:

sed 's\"//g'<'newfile.txt'>'outfile.txt'.

But yet another syntax error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:17:05+00:00Added an answer on June 6, 2026 at 8:17 am

    If you’re sure you want literal replacement, you just need to escape the quotes or use single quotes: replace('1 - "C1".', "c1") and so on (and to correct a couple of syntax-breaking typos). This, however, will only work on the first line, so there’s no point in reading the whole file then. To do a smarter job, you could use re.sub:

    with open('file.text') as input, open('newfile.txt','w') as output:
         for line in input:
             line = re.sub(r'^(?P<num>\d+) - "C(?P=num)".$',
                           lambda m: 'c' + m.groups()[0], line)
             line = re.sub(r'^E #(?P<num>\d+) - "C(?P=num)".$',
                           lambda m: 'E c' + m.groups()[0], line)
             output.write(line)
    

    In the sed command you seem to try to simply remove the quotes:

    sed 's/"//g' newfile.txt > outfile.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to remove duplicate strings from extremely big text file (100 Gb+) Since
I am having on xml from which i have to remove the one book
I have a command output from which I want to remove the double quotes
I have a section of code that I need to remove from multiple files
I have two functions that I'm using to add or remove slashes from a
This question risks being a duplicate e.g. remove double quotes from a string in
Although this code is from an algorithm text, I have a bit of a
I have to remove a branch from svn history for good. Normally I would
With python inotifyx, do I have to remove watch and close opened system file
I have following code to remove group from collection. Technically, there should be no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.