Reputation: 737
I am trying to write a script to take all the php.js functions and create a node.js library for them, Which means I have to figure out how to convert
this
function key (arr) {
to
key: function (arr) {
I know sed can do it, But I can't figure it out
Thanks for any help
Upvotes: 0
Views: 118
Reputation: 10039
sed "s/^ *function \{1,\}\([^ ]\{1,\}\) \{1,\}(/\1: function (/" file.js
replace the \s by " " assuming there is not tab in white space of the code
Upvotes: 0
Reputation: 41460
Here is an awk
to swap fields
awk '/function/ {t=$2":";$2=$1;$1=t} 1' file.js
key: function (arr) {
Upvotes: 0
Reputation: 68
sed 's/function\s\(.*\)(/\1: function(/g' file.js
That should do the trick
Upvotes: 2