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?

0

3 Answers 3

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
  • 1
    if you add -i, you do it in one go. Commented Oct 9, 2018 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"]} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.