adding characters end of line where line begins with..

Hi all,

using VI, can anyone tell me how to add some characters onto the end of a line where the line begins with certain charactars eg

a,b,c,.......,
r,s,t,........,
a,b,c,.......,

all lines in the above example starting with a,b,c, I want to add an x at the end of the line so the line file would be

a,b,c,.......,x
r,s,t,........,
a,b,c,.......,x

any help appreciated!
Regards
Satnam

ESCAPE
:
1,$s/\(^a.*,$\)/\1x
1 Like

HI, thanks for coming back to me..i noticed that your suggested command does not filter out on the lines starting with a,b,c? which is what i need it to do?
cheers
Sat

ESC
:%s/^a,b,c.*/&x/

% means "in the whole file" ... just a lazy typing for 1,$ :slight_smile:
but the substitution will occure only in the lines matching the pattern defined between the first / / since this pattern match the whole line that start with a,b,c you can then use & to refer to that match before you add the expected x this avoid \( \) \1 grouping stuff

@satnamx:

Previous command was updated, please have a look at it :wink:

@cabrao :
it works also without trailing / ?

smashed it!

much obliged :b: