I have 200k files in a single folder in linux server where i need to transform this files using regex here is the regex to find in text file
([^\s]+?.*)=((.*(?=,$))+|.*).*
now I need to replace it with below substitution value
"$1":"$2",
the above regex is working fine when i used them in python. the server which i am working does not support python, so i need to use bash commands. i have tried below bash command but it is not working
command:
sed -r 's/([^\s]+?.*)=((.*(?=,$))+|.*).*/"$1":"$2",/g' *20200502*
the above bash command is not working
Fixed your regex:
sed -E 's/([^[:space:]]+?.*)=((.*(=?,$))+|.*).*/"\1":"\2",/g' *20200502*
[^\\s]
by its POSIX ERE syntax equivalent [^[:space:]]
.?=,$
with =?,$
instead."$1":"$2"
with "\\1":"\\2"
.Kinda difficult to test but just analyzing your approach this might work:
sed -i -E "s/([^\s]+?.*)=((.*(?=,$))+|.*).*/\1$1\2$2/" *20200502*
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.