A
A
Atraides2018-08-15 15:09:31
bash
Atraides, 2018-08-15 15:09:31

It is necessary to translate the lines into one line in bash, what is the best way?

Greetings gentlemen, there is a text:

[
  "test_tag1",
  "тэг_2",
  "тэг_3",
  "тэг_4"
]

You need to make a script that would eventually translate all lines with values ​​in " " into one line separated by commas. for example: test_tag1, tag_2, tag_3, tag_4 Tell me
in which direction to think at least) there was an idea to use the while read line loop to read lines with awk as a separator, use a regular expression that would take the text between quotes and then add it all into one line $ a, $a1, etc. Or maybe it's easier to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bova, 2018-08-15
@Atraides

Maybe
x=`cat $my_file | grep -v "\[" | grep -v "\]" | sed s/\"//g | awk -vORS= '{print $1}'`

A
Atraides, 2018-08-15
@Atraides

Vladimir Boronin Thank you very much) what you need) did not know about awk -vORS= '{print $1}'` , but it turns out I googled badly)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question