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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:19:22+00:00 2026-06-10T18:19:22+00:00

I have a document containing many percent, plus, and pipe signs. I want to

  • 0

I have a document containing many percent, plus, and pipe signs. I want to replace them with a code, for use in TeX.

  • % becomes \textpercent.
  • + becomes \textplus.
  • | becomes \textbar.

This is the code I am using, but it does not work:

sed -i "s/\%/\\\textpercent /g" ./file.txt
sed -i "s/|/\\\textbar /g" ./file.txt
sed -i "s/\+/\\\textplus /g" ./file.txt

How can I replace these symbols with this code?

  • 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-10T18:19:24+00:00Added an answer on June 10, 2026 at 6:19 pm

    Test script:

    #!/bin/bash
    
    cat << 'EOF' > testfile.txt
    1+2+3=6
    12 is 50% of 24
    The pipe character '|' looks like a vertical line.
    EOF
    
    sed -i -r 's/%/\\textpercent /g;s/[+]/\\textplus /g;s/[|]/\\textbar /g' testfile.txt
    
    cat testfile.txt
    

    Output:

    1\textplus 2\textplus 3=6
    12 is 50\textpercent  of 24
    The pipe character '\textbar ' looks like a vertical line.
    

    This was already suggested in a similar way by @tripleee, and I see no reason why it should not work. As you can see, my platform uses the very same version of GNU sed as yours. The only difference to @tripleee’s version is that I use the extended regex mode, so I have to either escape the pipe and the plus or put it into a character class with [].

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

Sidebar

Related Questions

I have a document containing many quotation marks. I need to replace all pairs
I have a document containing many marks, but I want to convert it for
I have a document file containing HTML markup. I want to assign the contents
I have a pdf document containing several images. I want to retrieve names of
I have many HTML documents containing many HTML entities of Unicode code point representation,
I want to convert an XML document containing many elements within a node (around
I have an XML document containing contact information as seen below: <contact type=individual> <firstname>Some</firstname>
I have a string containing XML document using LinqtoXML What is the best way
Have a source xml document that uses namespace containing prefixes and a default namespace.
I have a huge XML document 200MB in size containing textual information. The data

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.