Search and Replace with Numbers

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 appreciated.


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.

Need Your Help

File upload / move temp not working on nginx

php file-upload nginx

So, i've read this question about move_uploaded_file() problems. However, on my apache-powered localhost lamp stack, its working just fine. So i think it may be a filesystem / path thing, and not a...

How to access values from angular $scope variable in MVC view?

javascript angularjs model-view-controller

The below function retrieves data from controller function and saves it to $scope.Details and redirect to payment view.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.