1

I have a line with thousands of lines like this:

{"100K";"0.00001";"10";"0.01"]}
{"101K";"0.0001";"100";"0.1"]}
{"102K";"1";"1000";"1"]}
{"102K";"1";"1000";"1"]}
{"103K";"0.01";"10000";"10"]}
{"104K";"0.1";"100000";"100"]}
{"105K";"1";"1000000";"1000"]}
{"109K";"0.000001";"1";"1"]}
{"120K";"0.000012";"12";"12"]}

I want to replace the first occurrence of ; in a line with :[

Making these lines equal to

{"100K":["0.00001";"10";"0.01"]}
{"101K":["0.0001";"100";"0.1"]}
{"102K":["1";"1000";"1"]}
{"102K":["1";"1000";"1"]}
{"103K":["0.01";"10000";"10"]}
{"104K":["0.1";"100000";"100"]}
{"105K":["1";"1000000";"1000"]}
{"109K":["0.000001";"1";"1"]}
{"120K":["0.000012";"12";"12"]}

how do I do that with sed or other unix command?

7
sed 's/;/:[/' file

{"100K":["0.00001";"10";"0.01"]}
{"101K":["0.0001";"100";"0.1"]}
{"102K":["1";"1000";"1"]}
{"102K":["1";"1000";"1"]}
{"103K":["0.01";"10000";"10"]}
{"104K":["0.1";"100000";"100"]}
{"105K":["1";"1000000";"1000"]}
{"109K":["0.000001";"1";"1"]}
{"120K":["0.000012";"12";"12"]}
  • 1
    if you add -i, you do it in one go. – Rui F Ribeiro Oct 9 '18 at 16:00
1

Since you tagged the question with :

awk '{ sub(/;/, ":["); print; }'
0

You can try with below 2 commands also:

perl -pne "s/;/:[/" filename
sed 's/;/:[/1' filename

Output:

{"100K":["0.00001";"10";"0.01"]}
{"101K":["0.0001";"100";"0.1"]}
{"102K":["1";"1000";"1"]}
{"102K":["1";"1000";"1"]}
{"103K":["0.01";"10000";"10"]}
{"104K":["0.1";"100000";"100"]}
{"105K":["1";"1000000";"1000"]}
{"109K":["0.000001";"1";"1"]}
{"120K":["0.000012";"12";"12"]}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.