0

So i have a text file with part of html code:

>>nano wynik.txt

with text:

1743: < a href="/currencies/lisk/#markets" class="price" data-usd="24.6933" data-btc= "0.00146882"

and i want to print only: 24.6933

I tried the way with the cut command but it does not work. Can anyone give me a solution?

7
  • What is the criteria for a number getting printed? Are you only worried about data-usd? Commented Jan 6, 2018 at 0:41
  • I suggest to use an XML/HTML parser (xmlstarlet, xmllint ...). Commented Jan 6, 2018 at 0:42
  • @ThomasSmyth result.txt is only a temporary file which is deleted at the end of the script, its content depends on what data I download from the website although the text pattern is always the same but the data-usd value is different, for example: 12.1594 or 1203.394, so the text length also it's different. I only need the data-usd value that I can capture into a variable or edit the file result.txt so that only this value is there. I hope you understand the message :). Commented Jan 6, 2018 at 0:50
  • Got it, thanks for clarifying. Commented Jan 6, 2018 at 0:50
  • Does the file really have 1743: at the beginning of the line? So it's not really HTML, it has extra formatting added? Commented Jan 6, 2018 at 0:53

1 Answer 1

2

With GNU grep and Perl Compatible Regular Expressions:

grep -Po '(?<=data-usd=").*?(?=")' file

Output:

24.6933
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.