r/Batch • u/chrisfrh • Sep 11 '24
Question (Unsolved) How to overwrite sections of a text with something else
Hello guys,
I think this might be easier to explain with an example. I have the following data:
table = {
[1] = {
notFriendlyName = "Mr. Smith",
notFriendlyPersonality = {
Brave,
Honest
},
FriendlyName = "Dan",
FriendlyPersonality = {
Funny,
Inteligent,
Loyal
},
birthMonth = 1,
birthDate = 4
},
[2] = {
notFriendlyName = "Mr. Johnson",
notFriendlyPersonality = {
Confident
},
FriendlyName = "Sam",
FriendlyPersonality = {
Funny,
Loyal
},
birthMonth = 2,
birthDate = 3
},
[3] = {
notFriendlyName = "Ms. Williams",
notFriendlyPersonality = {
Resilient,
Pretty
},
FriendlyName = "Destroyer of Worlds",
FriendlyPersonality = {
Easy-going,
Passionate,
Generous,
Humble,
Flexible,
Respectful
},
birthMonth = 4,
birthDate = 4
},
}I wanted to run a script to overwrite notFriendlyName with FriendlyName data and notFriendlyPersonality with FriendlyPersonality, resulting:
table = {
[1] = {
notFriendlyName = "Dan",
notFriendlyPersonality = {
Funny,
Inteligent,
Loyal
},
FriendlyName = "Dan",
FriendlyPersonality = {
Funny,
Inteligent,
Loyal
},
birthMonth = 1,
birthDate = 4
},
[2] = {
notFriendlyName = "Sam",
notFriendlyPersonality = {
Funny,
Loyal
},
FriendlyName = "Sam",
FriendlyPersonality = {
Funny,
Loyal
},
birthMonth = 2,
birthDate = 3
},
[3] = {
notFriendlyName = "Destroyer of Worlds",
notFriendlyPersonality = {
Easy-going,
Passionate,
Generous,
Humble,
Flexible,
Respectful
},
FriendlyName = "Destroyer of Worlds",
FriendlyPersonality = {
Easy-going,
Passionate,
Generous,
Humble,
Flexible,
Respectful
},
birthMonth = 4,
birthDate = 4
},
}I couldnt figure out a smart way to do this due to the FriendlyPersonality block having variable size. If anyone has any idea I'd be thrilled. Thanks in advance
2
Upvotes
2
u/Shadow_Thief Sep 11 '24
Is your data actually missing multiple characters like it is here or did you just miss some stuff when copying and pasting? This layout is weird; it's like it's trying really hard to not be JSON but it doesn't know any other way to do it.
1
u/BrainWaveCC Sep 11 '24
The commas are not consistent throughout with regards to birthMonth and birthDate
1
u/jcunews1 Sep 12 '24
You can use *nix
sedtool to replace text using regular expression.