Reputation: 127
I have a string which has a format like this :
{u city : u Zurich , u name : u Hauptbahnhof , u address : u Test address, C106, Bahnhofsstrasse }
I need to remove all the " u "
(with the spaces) and replace the ", u "
(with the spaces) with a line breaker, but i have no idea how i could do that.
Is it possible with sed?
Output should be like
{city :Zurich
name :Hauptbahnhof
address :Test address, C106, Bahnhofsstrasse }
Thank you guys
Upvotes: 0
Views: 152
Reputation: 85530
Use perl
command line substitution as below, used the \b
tags for matching exact words and not mess up with other strings.
perl -pe 's/\bu \b//g;' -pe 's/\b , \b/\n/g;' file
{city : Zurich
name : Hauptbahnhof
address : Test address, C106, Bahnhofsstrasse }
And as pointed by others, if it is a broken JSON
use jq
or other ways to fix it.
Upvotes: 1
Reputation: 241748
The following seems to work (with some whitespace differences):
's/, u /\n/g;s/\bu //g'
i.e. first replace all ", u "
with newlines, then remove all u
, where u
is not preceded by a word character.
Note that the output isn't a valid JSON.
Upvotes: 2