Alright so I've got list in JS formatted like so:
{ text:"item1here", link: "0"},
{ text:"item2here", link: "0"},
...
{ text:"item2000here", link: "0"}
The list has over 2,000 items in it, I need a way to get the link: "0" to match that entries number in the list, starting with 0 and going upwards. Obviously some kind of search and replace would work find. Any ideas on how to go about this? I'm on a Mac so any UNIX or OS X method would be greatly appreci开发者_如何转开发ated.
This should do it:
perl -e '$i=0; while(<>) { if(s/link\:\s+\"0\"/link: "$i"/){ $i++;} print; }' yourfilename > newfilename
There are lots more ways using various UNIX commands. Let me know if you need this explained in detail.
var i = 0;
for (var obj in names) {
obj.link = String(i);
i += 1;
}
(this is how you would do it programmatically in JavaScript)
精彩评论