mardi 6 décembre 2016

sed: get last n character in every matching line

so i have a file like that:

bla bla bla 
telephonenumber: 497621160119286
y y y    
xxxx   
telephonenumber: 4160119100
xxxx   
blabla 
telephonenumber: 160119126

I need to change the given file to that:

bla bla bla 
telephonenumber: 9286
y y y    
xxxx   
telephonenumber: 9100
xxxx   
blabla 
telephonenumber: 9126

Basically just get the list 4 Character of the number in a matching line

I figured out something like that:

sed '^http://telephonenumber:/s/^.*/(.\{4\}\)$/1\' givenfile

Can you guys give me some help? Thanks in Advance!

Aucun commentaire:

Enregistrer un commentaire