Sunday, 15 February 2015

Sed to replace certain number of occurences -


I place the script behind me and it works for the first occurrence of each line, but I try to do it Instead of one / (1) or the entire line (/ g) I am doing the first 2 events per line:

  sed -r '2, $ s / (^ * |, * ) ([AG]) / \ 1 \ U \ 2/1 ' 

Is there a way to do this either by creating or scripting SEED commands?

best I can offer

  sed -r ' 2, $ {s / (^ |)) * [es] / \ u and /; // \ U & amp; /; } ''  

\ u & amp; The trick uses the fact that the upper case version of the space is still a place; This is to reduce the recurrence because captures are no longer used, regex can be a bit simpler.

In the second s command, // is a stand-in for the most recent regex, so for the first time essentially the second The time is executed (at this time which was basically another presence). Since / 1 is not actually doing anything (the first is the default of the first instance), I took the liberty to remove it.


No comments:

Post a Comment