1

I want to grep data in between <td> and </td>

examples:

  • required 1 from <td>1</td>
  • required 6 from <td>6</td>

so how to get that data?

  • We need to see your input and desired output... – Ravexina Aug 2 '17 at 8:01
  • What do you want with that Data? Copy in a variable? – ADDB Aug 2 '17 at 8:01
  • 1
    Please edit your question and clarify. Where is the data? In a file? In a shell variable? Are the <td> and </td> on the same line? Can they have anything other than a number between them? Will there only be one pair per line? One per file? Many? We can't help you parse data you do not show us. – terdon Aug 2 '17 at 8:03
  • also, will the entire file consist of just one line with no linefeeds? (not uncommon with html fetched from a web server). and will the html you're fetching tomorrow be formatted the same as what you're fetching today while you're writing the script. – cas Aug 2 '17 at 8:34
  • @Ravexina i grep from one website till this and not able to grep that value so i need help – xyz_scala Aug 2 '17 at 8:57
2

Through grep if multiple times in a line:

grep -oP '(?<=<td>).*?(?=</td>)' infile.txt
1
6

Through awk and same if multiple times in a line:

awk -v FS="(<td>|</td>)" '{for(i=2;i<=NF;i+=2) print $I}' infile.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.