-1
val=$(curl https://www.geeksforgeeks.org | tr '\n' ' ' | tr -s [[:space::]] | grep -E client_id -e publication_id)

I have a requirement to fetch the particular value from curl command:

Sample I/P:
client_id:"15647",publication_id:["151","152","153"]

Output:

publication_id:["151,"152","153"]

I want to use grep command to fetch publication_id values from curl command in unix and store in variable

1 Answers1

1

One solution with , , and , as said in comments, you need a aware tool:

Javascript wget.js code (this is only to mimic wget, it's output only HTML, and the one generated by too):

const puppeteer = require('puppeteer');

(async () => {
    var url = process.argv[2];
    const browser = await puppeteer.launch({headless: true});
    const page = await browser.newPage();
    await page.goto(url, { waitUntil: 'networkidle2' });
    const html = await page.evaluate(() => document.documentElement.outerHTML);
    console.log(html);
    browser.close();
})()

code:

node wget.js 'https://www.geeksforgeeks.org' |
    xidel -e '//div[@id="g_id_onload"]/@data-client_id' 

Output:

388036620207-3uolk1hv6ta7p3r9l6s3bobifh086qe1.apps.googleusercontent.com
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223