Searches and replaces the zoo.color to zoo['color'] or zoo.animals to zoo['animals']:
cat zoo.js | sed -E "s/(zoo)(\.)([a-zA-Z0-9]*)/\1['\3']/g"|less
\1 = is the characters inside the first parenthesis w/c is the zoo
\3 = is the characters inside the third parenthesis which involves alpha-numeric
-E will interpret as regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE's)


3 comments:
unsay sed bai?
sed is a Unix/Linux utility that means for stream editor. You can even used it as a shell to interpret the language your using inside a shell script. sed is mostly used for parsing text files then doing some implementation on programming to transform data of your text file. Think like Perl or the famous Regular Expression. That's how it works.
Great find, thanks. Never forget to use the -E parameter, otherwise it won't work!!
Post a Comment