inserting some text into a file using 'awk' command
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
thanks a lot crts.
but could you please describe what /s/[0-9].*[0-9]/ stands for!?
i don' understand what is that for.
Code:
s/[0-9].*[0-9]/$newip/
is sed's substitution command. It works in the manner
Code:
s/pattern/replacement/
[0-9] is called a character class. It stands for any digit from 0..9.
The '.' stand for any character and the asterisk is a quantifer to the previous expression. So '.*' stands for any amount of any characters. So in the processed line anything that is enclosed between two digits will be replaced with $newip.
is sed's substitution command. It works in the manner
Code:
s/pattern/replacement/
[0-9] is called a character class. It stands for any digit from 0..9.
The '.' stand for any character and the asterisk is a quantifer to the previous expression. So '.*' stands for any amount of any characters. So in the processed line anything that is enclosed between two digits will be replaced with $newip.
thank you so mucn crts, that worked
but what if i want to insert a range of IP address like this;
ip address="192.168.1.10/24"
I've tried to add '/24' at the end of the read parameter ($new ip), but that does'n work.
want to add this replacement by script:
ip address="192.168.1.10/24"
----------------------------------------
and i used this command in my script
read -p "IP address:" newip
sed -ri 's/^(ip address=).*/\1"'newip/24'"/' filename
want to add this replacement by script:
ip address="192.168.1.10/24"
----------------------------------------
and i used this command in my script
read -p "IP address:" newip
sed -ri 's/^(ip address=).*/\1"'newip/24'"/' filename
that didn't work for me grail, any idea?
change your sed statement to
Code:
sed -ri "/^ip address=/ s|[0-9].*[0-9]|$newip|" file
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.