How to make:

```bash
xmllint --html --xpath '//div[starts-with(@id, "order_")]/@id' 2024.html
```
```
id="order_C0XXXXXXXX"
id="order_C0YYYYYYYY"
```

only return `order_C0XXXXXXXX` and `order_C0YYYYYYYY`?
Aug 24, 9:18pm

To extract only the values of the id attributes (e.g., order_C0XXXXXXXX and order_C0YYYYYYYY) without the id="..." formatting, you can modify your xmllint command to use the text() function or adjust the XPath expression to directly return the attribute values.

Here’s how you can do it:

Option 1: Use text() in XPath

bash
xmllint --html --xpath '//div[starts-with(@id, "order_")]/@id/text()' 2024.html

This will return:

text
order_C0XXXXXXXX
order_C0YYYYYYYY

Option 2: Use sed to strip the id="..." formatting

If the above doesn't work (depending on your xmllint version), you can pipe the output to sed to clean it up:

bash
xmllint --html --xpath '//div[starts-with(@id, "order_")]/@id' 2024.html | sed 's/id="\(.*\)"/\1/'

This will also return:

text
order_C0XXXXXXXX
order_C0YYYYYYYY

Explanation:

  • The XPath expression //div[starts-with(@id, "order_")]/@id/text() directly extracts the text value of the id attribute.
  • The sed command removes the id="..." wrapper, leaving only the value.
Aug 24, 9:18pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more