LINUX.ORG.RU

История изменений

Исправление tz4678, (текущая версия) :

~/work
➜ head -n10 output/alexa.json | fq 'this.headers.server'
Apple
Microsoft-IIS/10.0
ATS/8.0.8
Apache
gws
GitHub.com
gws

~/bin/fq:

#!/usr/bin/env node
const readline = require('readline')
async function run() {
  const rl = readline.createInterface(process.stdin)
  const filters = process.argv.slice(2).map(c => Function('return ' + c))
  for await (line of rl) {
    let rv = JSON.parse(line)
    for (const filter of filters) {
      rv = filter.call(rv)
    }
    if (rv)
      console.log(rv)
  }
}
run()
➜ head -n10 output/alexa.json | fq 'this.headers' 'this.server'
Apple
Microsoft-IIS/10.0
ATS/8.0.8
Apache
gws
GitHub.com
gws

Исправление tz4678, :

~/work
➜ head -n10 output/alexa.json | fq 'this.headers.server'
Apple
Microsoft-IIS/10.0
ATS/8.0.8
Apache
gws
GitHub.com
gws

~/bin/fq:

#!/usr/bin/env node
const readline = require('readline')
async function run() {
  const rl = readline.createInterface(process.stdin)
  const filters = process.argv.slice(2).map(c => Function('return ' + c))
  for await (line of rl) {
    let rv = JSON.parse(line)
    for (const filter of filters) {
      rv = filter.call(rv)
    }
    if (rv)
      console.log(rv)
  }
}
run()

Исправление tz4678, :

~/work
➜ head -n10 output/alexa.json | fq 'this.headers.server'
Apple
Microsoft-IIS/10.0
ATS/8.0.8
Apache
gws
GitHub.com
gws

~/bin/fq:

#!/usr/bin/env node
const readline = require('readline')
async function run() {
  const rl = readline.createInterface(process.stdin)
  const filters = process.argv.slice(2).map(c => Function('return ' + c))
  for await (line of rl) {
    const o = JSON.parse(line)
    const [result] = filters.map(f => f.call(o)).slice(-1)
    if (result) console.log(result)
  }
}
run()

Исходная версия tz4678, :

~/work
➜ head -n10 output/alexa.json | fq 'this.headers.server'
Apple
Microsoft-IIS/10.0
ATS/8.0.8
Apache
gws
GitHub.com
gws

~/bin/fq:

```js                                                                               
#!/usr/bin/env node
const readline = require('readline')
async function run() {
  const rl = readline.createInterface(process.stdin)
  const filters = process.argv.slice(2).map(c => Function('return ' + c))
  for await (line of rl) {
    const o = JSON.parse(line)
    const [result] = filters.map(f => f.call(o)).slice(-1)
    if (result) console.log(result)
  }
}
run()