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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -