reformat string using sed












0















I have a file containing lines



["foo"] = ".worldport 0 322.373138 -1487.853882 43.720089",
["bar"] = ".worldport 0 386.938000 212.299000 43.699400",
["baz"] = ".worldport 0 1239.120000 -286.705000 42.476400",


which I would like to be edited (keeping the name and values) with sed or awk to become...



["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,["position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,["position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,["position_z"]=42.476400,["map"]=0}









share|improve this question


















  • 1





    But what's your question?

    – Arkadiusz Drabczyk
    Dec 29 '18 at 12:58











  • What have you been trying to do and where have you been stuck?

    – Cyrus
    Dec 29 '18 at 13:56
















0















I have a file containing lines



["foo"] = ".worldport 0 322.373138 -1487.853882 43.720089",
["bar"] = ".worldport 0 386.938000 212.299000 43.699400",
["baz"] = ".worldport 0 1239.120000 -286.705000 42.476400",


which I would like to be edited (keeping the name and values) with sed or awk to become...



["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,["position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,["position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,["position_z"]=42.476400,["map"]=0}









share|improve this question


















  • 1





    But what's your question?

    – Arkadiusz Drabczyk
    Dec 29 '18 at 12:58











  • What have you been trying to do and where have you been stuck?

    – Cyrus
    Dec 29 '18 at 13:56














0












0








0








I have a file containing lines



["foo"] = ".worldport 0 322.373138 -1487.853882 43.720089",
["bar"] = ".worldport 0 386.938000 212.299000 43.699400",
["baz"] = ".worldport 0 1239.120000 -286.705000 42.476400",


which I would like to be edited (keeping the name and values) with sed or awk to become...



["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,["position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,["position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,["position_z"]=42.476400,["map"]=0}









share|improve this question














I have a file containing lines



["foo"] = ".worldport 0 322.373138 -1487.853882 43.720089",
["bar"] = ".worldport 0 386.938000 212.299000 43.699400",
["baz"] = ".worldport 0 1239.120000 -286.705000 42.476400",


which I would like to be edited (keeping the name and values) with sed or awk to become...



["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,["position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,["position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,["position_z"]=42.476400,["map"]=0}






regex sed awk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '18 at 12:49









djjeffdjjeff

61




61








  • 1





    But what's your question?

    – Arkadiusz Drabczyk
    Dec 29 '18 at 12:58











  • What have you been trying to do and where have you been stuck?

    – Cyrus
    Dec 29 '18 at 13:56














  • 1





    But what's your question?

    – Arkadiusz Drabczyk
    Dec 29 '18 at 12:58











  • What have you been trying to do and where have you been stuck?

    – Cyrus
    Dec 29 '18 at 13:56








1




1





But what's your question?

– Arkadiusz Drabczyk
Dec 29 '18 at 12:58





But what's your question?

– Arkadiusz Drabczyk
Dec 29 '18 at 12:58













What have you been trying to do and where have you been stuck?

– Cyrus
Dec 29 '18 at 13:56





What have you been trying to do and where have you been stuck?

– Cyrus
Dec 29 '18 at 13:56










1 Answer
1






active

oldest

votes


















0














A perl way:



perl -ape 's/ = ".w+h+(d+)h+(S+)h+(S+)h+(S+?)",/={["position_x"]=$2,["position_y"]=$3,[position_z"]=$4,["map"]=$1}/' file.txt
["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,[position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,[position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,[position_z"]=42.476400,["map"]=0}


Explanation:



w+     # 1 or more word characters
d+ # 1 or more digits
h+ # 1 or more horizontal spaces
S+ # 1 or more NON space characters





share|improve this answer
























  • this worked perfectly thanks +1 rep

    – djjeff
    Dec 30 '18 at 7:55











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1388727%2freformat-string-using-sed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














A perl way:



perl -ape 's/ = ".w+h+(d+)h+(S+)h+(S+)h+(S+?)",/={["position_x"]=$2,["position_y"]=$3,[position_z"]=$4,["map"]=$1}/' file.txt
["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,[position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,[position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,[position_z"]=42.476400,["map"]=0}


Explanation:



w+     # 1 or more word characters
d+ # 1 or more digits
h+ # 1 or more horizontal spaces
S+ # 1 or more NON space characters





share|improve this answer
























  • this worked perfectly thanks +1 rep

    – djjeff
    Dec 30 '18 at 7:55
















0














A perl way:



perl -ape 's/ = ".w+h+(d+)h+(S+)h+(S+)h+(S+?)",/={["position_x"]=$2,["position_y"]=$3,[position_z"]=$4,["map"]=$1}/' file.txt
["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,[position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,[position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,[position_z"]=42.476400,["map"]=0}


Explanation:



w+     # 1 or more word characters
d+ # 1 or more digits
h+ # 1 or more horizontal spaces
S+ # 1 or more NON space characters





share|improve this answer
























  • this worked perfectly thanks +1 rep

    – djjeff
    Dec 30 '18 at 7:55














0












0








0







A perl way:



perl -ape 's/ = ".w+h+(d+)h+(S+)h+(S+)h+(S+?)",/={["position_x"]=$2,["position_y"]=$3,[position_z"]=$4,["map"]=$1}/' file.txt
["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,[position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,[position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,[position_z"]=42.476400,["map"]=0}


Explanation:



w+     # 1 or more word characters
d+ # 1 or more digits
h+ # 1 or more horizontal spaces
S+ # 1 or more NON space characters





share|improve this answer













A perl way:



perl -ape 's/ = ".w+h+(d+)h+(S+)h+(S+)h+(S+?)",/={["position_x"]=$2,["position_y"]=$3,[position_z"]=$4,["map"]=$1}/' file.txt
["foo"]={["position_x"]=322.373138,["position_y"]=-1487.853882,[position_z"]=43.720089,["map"]=0}
["bar"]={["position_x"]=386.938000,["position_y"]=212.299000,[position_z"]=43.699400,["map"]=0}
["baz"]={["position_x"]=1239.120000,["position_y"]=-286.705000,[position_z"]=42.476400,["map"]=0}


Explanation:



w+     # 1 or more word characters
d+ # 1 or more digits
h+ # 1 or more horizontal spaces
S+ # 1 or more NON space characters






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 29 '18 at 15:17









TotoToto

3,65391226




3,65391226













  • this worked perfectly thanks +1 rep

    – djjeff
    Dec 30 '18 at 7:55



















  • this worked perfectly thanks +1 rep

    – djjeff
    Dec 30 '18 at 7:55

















this worked perfectly thanks +1 rep

– djjeff
Dec 30 '18 at 7:55





this worked perfectly thanks +1 rep

– djjeff
Dec 30 '18 at 7:55


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1388727%2freformat-string-using-sed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Aardman Animations

Are they similar matrix

“minimization” problem in Euclidean space related to orthonormal basis