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 6789959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:40:04+00:00 2026-05-26T17:40:04+00:00

In writing latex, usually there is a bibliography file, which sometimes contains _ ,

  • 0

In writing latex, usually there is a bibliography file, which sometimes contains _, &, or $. For example, the journal name “Nature Structural & Molecular Biology”, the article title “Estimating The Cost Of New Drug Development: Is It Really $802 Million?”, and the volume number “suppl_2”.

So I need to convert these symbols into \_, \&, and \$ respectively, i.e. adding a backslash in front, so that latex compiler can correctly identify them. I want to use sed to do the conversion. So I tried

sed 's/_/\_/' <bib.txt >new.txt

but the generated new.txt is exactly the same as bib.txt. I thought _ and \ needed to be escaped, so I tried

sed 's/\_/\\\_/' <bib.txt >new.txt

but no hope either. Can somebody help? Thanks.

  • 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-05-26T17:40:04+00:00Added an answer on May 26, 2026 at 5:40 pm

    You’re running into some difficulties due to how the shell handles strings. The backslash needs to be doubled:

    sed 's/_/\\_/g'
    

    Note that I’ve also added a ‘g’ to indicate that the replacement should applied globally on the lines, not just to the first match.

    To handle all three symbols, use a character class:

    sed 's/[_&$]/\\&/g'
    

    (The ampersand in the replacement text is a special character referring to the matched text, not a literal ampersand character.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I'm writing a Latex file, sometimes I need to remove all files which
which package would you use for writing algorithms in LaTeX? I know about algorithm,
I am writing my MSc with LaTeX and I have the problem that sometimes
I'm writing a document in Lyx, an editor for Latex. Is there any fast
I’m writing a LaTeX package which needs to use \write18 . Some of the
I use the following C-ish indentation/bracing style when writing LaTeX code: \foo{ blah blah...
LaTeX is a wonderful language for writing documents. With the hyperref package and pdflatex
I'm writing an in-house module to generate a small LaTeX PDF. Within the module,
While writing in LaTeX, I happened to type something like $ variable = test
I'm writing a LaTeX document in vim, and I have it hard wrapping at

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.