You're viewing a comment by Sundro and its responses.

Sundro Permalink
May 21, 2015, 17:21

thank you all for your contribution!! I have a problem, can one of you sed geeks help me? I need to identify port and change one digit. Ports are 4 digit long. 5121, 5123 for example below. and want to make it 5221, 5223 etc.. please please appreciate any help!

R2_SC_GOLDEN_STATE=5121 554,5122 554,5123 554

Comment Responses

Anirudh Permalink
February 01, 2016, 14:43

In plain sed, it can be done like as shown below:



   s/^//; trst

   # add 100 to a 4-digit number enclosed in \n
   s/\(\n[0-9]\)[0]/\11/; ta
   s/\(\n[0-9]\)[1]/\12/; ta
   s/\(\n[0-9]\)[2]/\13/; ta
   s/\(\n[0-9]\)[3]/\14/; ta
   s/\(\n[0-9]\)[4]/\15/; ta
   s/\(\n[0-9]\)[5]/\16/; ta
   s/\(\n[0-9]\)[6]/\17/; ta
   s/\(\n[0-9]\)[7]/\18/; ta
   s/\(\n[0-9]\)[8]/\19/; ta
   s/\(\n\)[0][9]/\110/;  ta
   s/\(\n\)[1][9]/\120/;  ta
   s/\(\n\)[2][9]/\130/;  ta
   s/\(\n\)[3][9]/\140/;  ta
   s/\(\n\)[4][9]/\150/;  ta
   s/\(\n\)[5][9]/\160/;  ta
   s/\(\n\)[6][9]/\170/;  ta
   s/\(\n\)[7][9]/\180/;  ta
   s/\(\n\)[8][9]/\190/;  ta
   s/\(\n\)[9][9]/\100/;  ta

   s/^/\n/; D


Or, with perl you could do:

perl -lpe 's/\b(\d\d)(?=\d\d\b)/int(($1+1)\/100)-1?$1+1:"00"/eg'

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "0day_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.