Replace First field of a file

Hello everyone,

I have a file with few fields and i want to replace the first field with new value, here is the example what i want to do,

I have file in dis format-

00222767 083957 00G001 7.83 11.0000 0 2015-08-08 1015400514

00222767 083957 00G001 5.80 11.0000 0 2015-08-08 1015400514

00222767 083957 00G001 3.23 11.0000 0 2015-08-08 1015400514

00222767 083957 00G001 2.48 11.0000 0 2015-08-08 1015400514

00222767 083957 00G001 3.18 11.0000 0 2015-08-08

And i want output as like that:- replace 00222767 with new value 00222779

00222779 083957 00G001 7.83 11.0000 0 2015-08-08 1015400514

00222779 083957 00G001 5.80 11.0000 0 2015-08-08 1015400514

00222779 083957 00G001 3.23 11.0000 0 2015-08-08 1015400514

00222779 083957 00G001 2.48 11.0000 0 2015-08-08 1015400514

Can anyone tell me the step of regular expression for this replacement

Thanks

Why not open with text editor and do the replacement? :smiley:

1 Like

Indeed a good solution :lol:

Here is my pseudo code (based on your sample input only)

1> Use getFile and store the file content in a string variable
2> Compute a sub-string (store 00222767 in some variable)
3> Replace 00222767 with 00222779 and store it in a string variable
4> Use writeToFile/stringToFile to write the content in to a file

OR

Using regex /^00222767 /

Let me know if you have a better or alternate approach.