I Have a file which contains multiple lines.I want only few things from that output.Below is the output i am getting from server.
Output:
"az": "nova",
"cloud": "envvars",
"config_drive": "",
"created": "2016-08-19T17:21:24Z",
"flavor": {
"id": "4",
"name": "m1.large"
},
"hostId": "f714baee5967dc17e7d36c7b72eb92a4f1ab68d9782fa90a968ceae5",
"human_id": "dsc-test-3",
"id": "3f0a1188-c151-4e5e-9930-969d0423601b",
"image": {
"id": "7f4ad1f4-6fab-4978-b65a-ec4b9a407c5c",
"name": "mitel-dsc-7.9-9.15_3nic"
},
"interface_ip": "172.16.17.15",
"key_name": "key1",
"metadata": {},
"name": "dsc-test-3",
"networks": {
"dsc-InterInstance": [
"172.16.18.15"
],
"dsc-OAM": [
"172.16.16.20"
],
"dsc-sig": [
"172.16.17.15",
"10.10.72.15"
]
},
My intention is to get below things
Required:
"networks": {
"dsc-InterInstance": [
"172.16.18.15"
],
"dsc-OAM": [
"172.16.16.20"
],
"dsc-sig": [
"172.16.17.15",
"10.10.72.15"
]
}
Try this method
sed -n '/networks.*{/,/}/p' fileName
Outputs:
"networks": {
"dsc-InterInstance": [
"172.16.18.15"
],
"dsc-OAM": [
"172.16.16.20"
],
"dsc-sig": [
"172.16.17.15",
"10.10.72.15"
]
}
Awk solution:
awk '/"networks"/,/}/' file.txt
This gives the output
"networks": {
"dsc-InterInstance": [
"172.16.18.15"
],
"dsc-OAM": [
"172.16.16.20"
],
"dsc-sig": [
"172.16.17.15",
"10.10.72.15"
]
},
The syntax used here is /start_regex/,/stop_regex/, which starts matching when a line matches start_regex and stops matching after a line matches stop_regex (so all the lines in between also get matched). Since no action is specified, the default {print} action is used.
Compared to your requirement, this outputs an extra , on the last line, since that comma is present in the input. If that is unacceptable, you could get rid of it using the action {sub("},","}");print}. Or by using sed as in the other answer.
... and the tagged grep solution as well:
$ cat file|tr '\n' _| grep -o \[^_\]*\"networks\"\[^}\]*}|tr _ '\n'
"networks": {
"dsc-InterInstance": [
"172.16.18.15"
],
"dsc-OAM": [
"172.16.16.20"
],
"dsc-sig": [
"172.16.17.15",
"10.10.72.15"
]
}
ie. change every \n to _, grep out the requested block and put the \n back. _ may not be the best choice for a substitute but works in this particular case.
With GNU awk for multi-char RS and RT you can just use a regexp to describe the string you're looking for:
$ awk -v RS='"networks": {[^}]+}' 'RT{print RT}' file
"networks": {
"dsc-InterInstance": [
"172.16.18.15"
],
"dsc-OAM": [
"172.16.16.20"
],
"dsc-sig": [
"172.16.17.15",
"10.10.72.15"
]
}
Related
I have the following polygon displayed on a map:
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-125.59984949809844,
45.262153541142055
],
[
-64.97100463461506,
39.503280047917194
],
[
-71.53494497281665,
25.360849581306127
],
[
-121.81059696453559,
26.995032595715646
],
[
-125.59984949809844,
45.262153541142055
]
]
]
},
"properties": {}
}
Calling
console.log(booleanPointInPolygon([-98.65195, 49.42827], polygon)); //logs false
console.log(booleanPointInPolygon([-106.53965, 27.69895], polygon)); //logs true
when the expected output should be the opposite. I'm pretty sure my data is in the right form [longitude, latitude], I am wondering what's giving me the wrong output?
I faced with the issue when I try to search for several words including a special character (section sign "§").
Example: AB § 32.
I want all words "AB", "32" and symbol "§" to be included in found documents.
In some cases document can be found, in some not.
If my document contains the following text then search finds it:
Lagrum: 32 § 1 mom. första stycket a) kommunalskattelagen (1928:370) AB
But if document contains this text then search doesn't find:
Lagrum: 32 § 1 mom. första stycket AB
For symbol "§" I use UT8-encoding "\xc2\xa7".
Index uses "lucene.swedish" analyzer.
"Content": [
{
"analyzer": "lucene.swedish",
"minGrams": 4,
"tokenization": "nGram",
"type": "autocomplete"
},
{
"analyzer": "lucene.swedish",
"type": "string"
}
]
Query looks like:
{
"index": "test_index",
"compound": {
"filter": [
{
"text": {
"query": [
"111111111111"
],
"path": "ProductId"
}
},
],
"must": [
{
"autocomplete": {
"query": [
"AB"
],
"path": "Content"
}
},
{
"autocomplete": {
"query": [
"\xc2\xa7",
],
"path": "Content"
}
},
{
"autocomplete": {
"query": [
"32"
],
"path": "Content"
}
}
],
},
"count": {
"type": "lowerBound",
"threshold": 500
}
}
The question is what is wrong with the search and how can I get a correct result (return both above mentioned documents) ?
Focusing only on the content field, here is an index definition that should work for your requirements. The docs are here. Let me know if this works for you.
{
"mappings": {
"dynamic": false,
"fields": {
"content": [
{
"type": "autocomplete",
"tokenization": "nGram",
"minGrams": 4,
"maxGrams": 7,
"foldDiacritics": false,
"analyzer": "lucene.whitespace"
},
{
"analyzer": "lucene.swedish",
"type": "string"
}
]
}
}
}
I have the following syntax:
test: name {
param_name: value
another_param: value2
test: [12, "asd"]
test2: [
"test__",
"test3"
]
}
My logic here is as follows:
Detect scopes as multi-line match
"begin": "([a-z_]+)\\s?:\\s?([a-z_\\+]+)?\\s?(\\{)",
"end": "(\\})",
In the patterns section of the above, add parameters with multiline matching
"begin": "(?!sql)([a-z\\_]*)\\s?:",
"end": "(?<=\\n)",
And then in the patterns of that I have array
"begin": "\\[",
"end": "\\]",
The problem is that test: [12, "asd"] is correctly defined as
test - parameter name
[12, "asd"] - parameter value + array
but I can't get it to work on the multi-line value. It only recognises the opening [ as array.
At first I thought I understood the reason why. The parameters finishes when it sees a new line, hence the second line of an array will not be matched. So I added array to the main scope pattern and that's when my understanding ends.
Full file:
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "QQQL",
"patterns": [
{"include": "#scopes"},
{"include": "#parameters"}
],
"repository": {
"scopes": {
"name": "source.qqql.scope",
"begin": "([a-z_]+)\\s?:\\s?([a-z_\\+]+)?\\s?(\\{)",
"end": "(\\})",
"patterns": [
{"include": "#scopes"},
{"include": "#array"},
{"include": "#parameters"}
]
},
"parameters": {
"name": "source.qqql.parameter",
"begin": "(?!sql)([a-z\\_]*)\\s?:",
"end": "(?<=\\n)",
"beginCaptures": {
"1": {
"name": "source.qqql.parameter.name"
}
},
"patterns": [
{"include": "#array"},
{
"name": "source.qqql.parameter.value",
"match": "(.*)",
"captures": {
"1": {
"patterns": [
{"include": "#array"}
]
}
}
}
]
},
"array": {
"name": "source.qqql.array",
"begin": "\\[",
"end": "\\]",
"patterns": [
{"include": "#strings"},
{
"name": "source.qqql.array.delimiter",
"match": "\\,"
}
]
}
},
"scopeName": "source.qqql"
}
What I expected is that the inclusion of array in scopes would solve the problem but somehow it doesn't.
I have a data source A and I'd like to create a new data source B containing just the last element of A. What is the best way to do this in Vega?
This is relatively straight forward to do. Although I am slightly confused by your use of "max" in the aggregation since this isn't the last value?
Either way here is my solution for obtaining the last value in a dataset using this series of transforms,
transform: [
{
type: window
ops: [
row_number
]
}
{
type: joinaggregate
fields: [
row_number
]
ops: [
max
]
as: [
max_row_number
]
}
{
type: filter
expr: datum.row_number==datum.max_row_number
}
]
I was able to get this working in the Vega Editor using the following:
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"data": [
{
"name": "source",
"url": "https://raw.githubusercontent.com/vega/vega/master/docs/data/cars.json",
"transform": [
{
"type": "filter",
"expr": "datum['Horsepower'] != null && datum['Miles_per_Gallon'] != null && datum['Acceleration'] != null"
}
]
},
{
"name": "avg",
"source":"source",
"transform":[
{
"type":"aggregate",
"groupby":["Horsepower"],
"ops": ["average"],
"fields":["Miles_per_Gallon"],
"as":["Avg_Miles_per_Gallon"]
}
]
},
{
"name":"last",
"source": "avg",
"transform": [
{
"type": "aggregate",
"ops": ["max"],
"fields": ["Horsepower"],
"as": ["maxHorsepower"]
},
{
"type": "lookup",
"from": "avg",
"key": "Horsepower",
"fields": ["maxHorsepower"],
"values": ["Horsepower","Avg_Miles_per_Gallon"]
}
]
}
]
}
maxHorsepower
Horsepower
Avg_Miles_per_Gallon
230
230
16
I'd be interested to know if there are better ways, but this worked for me.
I'd like to prevent src/config.js to be bundled in scripts/app-bundle.js
I saw that previously the syntax was:
"bundles": {
"dist/app-build": {
"includes": [
"[**/*.js]",
"**/*.html!text",
"**/*.css!text",
"cloneya",
"dexie",
"jquery",
"jquery-ui",
"medium-editor-webpack",
"moment",
"polymer/mutationobservers",
"safe-json-stringify"
],
excludes: [
"config.js" // So our wildcard globbing doesn't include this config file
],
...
However the new syntax is different: aurelia.json:
"bundles": [
{
"name": "app-bundle.js",
"source": [
"[**/*.js]",
"**/*.{css,html}"
],
"excludes" : [
"**/config.js"
]
},
My temptative 'exclude' statement doesn't do the trick
Solution is actually given on the GitHub page: https://github.com/aurelia/cli
Optionally, you can define an exclude list by setting the source
property to be an object containing both an include and exclude array
of patterns. This is helpful when you're trying to define multiple
bundles from your source code.
{
"name": "app-bundle.js",
"source": {
"include": [
"[**/*.js]",
"**/*.{css,html}"
],
"exclude": [
"**/sub-module/**/*",
]
}
},
{
"name": "sub-module-bundle.js",
"source": [
"**/sub-module/**/*",
]
}
Make sure you have version > 0.19.0