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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:04:43+00:00 2026-06-07T06:04:43+00:00

I need help for some command for handle the following situation. I search on

  • 0

I need help for some command for handle the following situation.
I search on net for help but i can’t succeed to find solution.

Problem is:

I have a xml file named as “temp.xml”
The text in the xml file is for example

<?xml version="1.0" encoding="utf-8"?>
<NoteData Note_Nbr="312" Data_Revision="2" Note_Revision="1" />

I want to save only Note_Nbr to my variable x (312)

I try a something but it doesn’t work.

 X=$(sed  -r  's/[^|]*(Note_Nbr=")(\d\d\d)([^|]*)/2 /' temp.xml )

Thank you for your helps.

  • 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-07T06:04:44+00:00Added an answer on June 7, 2026 at 6:04 am

    The right way to do this is with a real XML parser:

    x=$(xmllint --xpath 'string(/NoteData/@Note_Nbr)' test.xml)
    

    …or, if you have XMLStarlet rather than a new enough xmllint:

    x=$(xmlstarlet sel -t -m '/NoteData' -v @Note_Nbr -n <test.xml)
    

    See also this answer: https://stackoverflow.com/a/1732454/14122

    Now, if you only wanted to work with literal strings, you could build something fragile that looked like this, using parameter expansion:

    s='<NoteData Note_Nbr="312" Data_Revision="2" Note_Revision="1" />'
    s=${s#* Note_Nbr=\"}; s=${s%%\"*}; echo "$s"
    

    Alternately, you could use native regular expression support within bash (note that this functionality is a bash extension not present in POSIX sh):

    s='<NoteData Note_Nbr="312" Data_Revision="2" Note_Revision="1" />'
    re='Note_Nbr="([^"]+)"'
    if [[ $s =~ $re ]]; then
      match="${BASH_REMATCH[1]}"
    else
      echo "ERROR: No match found" >&2
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I need some help on but I feel I'm
I'm new to java and really need some help. I created a command line
I need help debugging some odd file behavior in Python. Take the following script
Need some help with this problem in implementing with XSLT, I had already implemented
I need some help with an excel command. I got two excel files, with
I need some help writing a class that can go through other java files
I'm working on learning Windows PS - but until than I need some help
I have a CKEditor custom plugin I'm trying to write, but need some help
I need some help on parsing the Command Line for a lua file. I
I need help figuring out some regular expressions. I'm running the dig command and

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.