1

I have 2 query which give me the results:

  1. service
  2. number of service

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
3
  • You can write a bash script for this. Commented Oct 5, 2018 at 11:21
  • 1
    @rafal1337, could you please post sample Input_file of yours in your post and let us know then? Commented Oct 5, 2018 at 11:24
  • @RavinderSingh13 this is json file. I parsing him to my expected output. Commented Oct 5, 2018 at 11:37

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

{ ... "name": "service1 ... "customfield_10090": "1.2.3" } }, ... "name": "service2" } ... ], "customfield_10090": "23.3.2" This is shortened json file.
In my case dont work - jq: error (at test:42): Cannot index string with string "customfield_10090" This is my entire json file: pastebin.com/gUU1x70j
You have to adjust the paths to the desired parameters: jq '.issues[].fields | .components[].name + ":" + .customfield_10090' test.json
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.