Reputation: 184
I have 2 query which give me the results:
example:
root@:~/elo# cat test | grep name | grep -v expand | cut -c 22- | rev | cut -c 3- | rev
service1
service2
root@:~/elo# cat test | grep customfield | cut -c 31- | rev | cut -c 2- | rev
2.3.4
55.66
I want to connect first value from first query with first value from second query etc. In this example should be:
service1:2.3.4
service2:55.66
Upvotes: 1
Views: 198
Reputation: 434
Without a sample file, it is hard to write a working example. But I see, both values are from the same text file and the same line. Therefore I would use awk to do it:
$ cat text
service1;some_other_text;2.3.4
service2;just_some_text;55.66
$awk -F ";" '{printf "%s:%s\n", $1, $3}' test
service1:2.3.4
For a JSON file, it would be easier if you can use jg (e.g. apt-get install jg):
$ cat test.json
[
{
"name": "service1",
"customfield_10090": "1.2.3"
},
{
"name": "service2",
"customfield_10090": "23.3.2"
}
]
$jq '.[] | .name + ":" + .customfield_10090' test.json | sed 's/"//g'
service1:1.2.3
service2:23.3.2
The sed is necessary to eliminate the quotes.
Upvotes: 1
Reputation: 242333
You can use paste
:
paste -d: <(grep name test| grep -v expand | cut -c 22- | rev | cut -c 3- | rev) \
<(grep customfield test | cut -c 31- | rev | cut -c 2- | rev)
But there might be better ways. If the input is json, you can probably use jq
for a shorter and more efficient solution.
Upvotes: 0