Edit line a textfile using linux shell -


i need change ip-address in text-file using linux-shell. how can that? know great source regular expressions?

the textfile.txt contains sth this:

# text text ffeefe  whatever text text ffeefe  # text text ffeefe  # ipaddress : 192.168.200.40 # # text text ffeefe # whatever text text ffeefe  # text text ffeefe  

this looking for:

sed -i / find xxx.xxx.xxx.xxx / 192.168.200.41 / textfile.txt 

the ip in format xxx.xxx.xxx.xxx e.g. 192.168.200.40

although fedorqui right asking more information occurring of ip after specific content, i'll provide (easy) solution finding ipv4 string.

the expression is:

[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ 

using in sed looks this:

sed -i -r 's/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/newip/' file 

on other hand, if fixed "ipaddress : " before ip, op should use ip want.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -