Trying to create a function that will Append content to lines in a file that match a certain regex condition
AccountFile.txt
1 {
2 "account": "123456",
3 "MoreAccounts": { //Some-Comment-1
4 "evenMoreAccounts: {
5 "Hello" : "World"
6 }
7 }
8 }
So if the regex to match is .*Some-Comment-1
it will match the 3rd line.
And For example say I wanted to insert the text
"anotherAccount" : {
"HelloWorld" : "2"
},
under the line that matches the regex above, the output of my program should be:
1 {
2 "account": "123456",
3 "MoreAccounts": { //Some-Comment-1
4 "anotherAccount" : {
5 "HelloWorld" : "2"
6 },
7 "evenMoreAccounts: {
8 "Hello" : "World"
9 }
10 }
11 }
The problem Im facing is the formatting, how can I make sure the text I want to insert always matches the surrounding text's formatting for any file extension .py, .yaml, .txt, .json, .java
Right now my function is outputting something that looks like this
1 {
2 "account": "123456",
3 "MoreAccounts": { //Some-Comment-1
4 "anotherAccount" : {
5 "HelloWorld" : "2"
6 },
7 "evenMoreAccounts: {
8 "Hello" : "World"
9 }
10 }
11 }
Is there any good external library that can do this for me? All help would be appreciated thanks
Or Even a Java Library that could beautify any text file would be useful
The programming language im using to write this is Java, so a java function or library would be helpful
Things Ive looked into
- JAlopy ~ only works for java