unix - editing text files with perl -
I am trying to edit a text file that looks like this:
< Code> TYPE = Ethernet HWADDR = 00: .... IPv6INIT = no MTU = 1500 IPADRR = 1 2.168.2.247 ...
(This is actually / etc / sysconfig / Every time I want to modify it, instead of reading and rewriting the file, I felt that I had grep, sed, awk or native text provided in Perl, on the network-script / ifcfg-file red cap linux)I could use Arsing functionality. For example, if I want to change the IPDDR field of the file, is there a way that I can just retrieve the straight line? Maybe something like this
grep 'ipaddr =' & lt; Filename & gt;
But to add some additional logic to modify that row? I'm a bit new in Unix based text processing languages, so bear with me ...
Thanks! Here is a Pearl Inlineer to replace the IPADRR value with IP address 127.0.01.
It is very low that you should be able to see what you need to change the other fields: *
perl -p -i.orig -e 's / ^ Ipaddr =. * $ / Ipadr = 127.0.0.1 / 'filename
This name will give the name of "filename" "filename.orig", and the new version of the file will be written in "filename".
The Pearl command line options have been explained (thanks to the Reminder Toolk!), And the syntax of the Perl Regular Expression.
* Regular expression ^ IPADDR =. $$
, divided into components, this means:
^ line # ipddr = #boot to start plain text: match "ipadrr =" . * # After any type of any character (`.` means" any single letter ";` `` means any of them ") Bind to the end of the $ # line
Comments
Post a Comment