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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:50:39+00:00 2026-06-13T17:50:39+00:00

I have a line similar to this grep -oP data-context-item-title=.*.data-context-item-id web.html | cut -d”

  • 0

I have a line similar to this

grep -oP "data-context-item-title=.*.data-context-item-id" web.html | cut -d'"' -f2

I know this line correctly works since I used it on the terminal and it gave me the desired output. However, I want to put this line in a bash script. so I have this so far

title="$(grep -oP 'data-context-item-title=.*.data-context-item-id' web.html | cut -d'"' -f2)"

This is a problem because it matched the first “(quotation) with the cut’s “(quotation). Is there anyway to avoid it?

Output without the cut function is something similar to this

data-context-item-title="Some long title" data-context-item-id
data-context-item-title="Another very long title" data-context-item-id

Keep in mind, I can’t use any sed or awk commands to replace cut.

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-06-13T17:50:41+00:00Added an answer on June 13, 2026 at 5:50 pm

    Since you’re using bash, it would be safe enough to use:

    title=$(grep -oP 'data-context-item-title=.*.data-context-item-id' web.html | cut -d'"' -f2)
    

    This will preserve the internal spacing (in particular newlines) in the variable, as you’d be able to see if you did:

    echo "$title"
    

    I’m of the opinion that if you managed to find a UNIX™ 7th Edition Bourne Shell to use, then omitting the double quotes around the $(...) notation (or, more accurately, the `...` notation) would not be safe, but it does seem to work safely on modern shells (say those last updated in the current millennium, rather than in the previous one). The difficulty is in finding an old Bourne Shell on which to verify my now shaky (because distant) recollection.

    What puzzles me, though, is that with both bash 3.2 (system) and 4.2 (home-built) running on Mac OS X 10.7.5, your code works correctly for me both with and without the double quotes around the $(...). Which version of bash are you using, and on which platform?

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

Sidebar

Related Questions

I have a question very similar to this: How to know if a line
I Have an Excel 2003 file with a line similar to this: I need
I have a lagre data frame which looks similar to this format: line1 line2<tab>value1
I have the following file full of lines similar to this: line = 'Weclome
I have some data.. it looks similar to this: 0423 222222 ADH, TEXTEXT 0424
In my code I have a line similar to this: rval = subprocess.call([mkdir,directoryName], shell=True)
With grep , you have a --null-data option -z, --null-data a data line ends
I know I have similar question with this post: Django tutorial on remote server:
I have a plot similar to this one: b <- data.frame(x=c(1,2,3,1,2,3,1,2,3,1,2,3),y=c(1,2,3,1.5,1.9,2.5,3,2,1,2.9,1.8,1.5),c=c(1,1,1,2,2,2,1,1,1,2,2,2),f=c(b,b,b,b,b,b,a,a,a,a,a,a)) ggplot(b,aes(x=x,y=y,color=c,group=c))+geom_line()+facet_grid(f ~ .)
I have a line chart that is updated every so and so seconds, similar

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.