Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
i wanna edit a file using echo command.
suppose i wanna edit ntp.conf file and i wanna put # in front of some consicutive lines and wanna edit some line.
let say i wanna edit
IMHO, echo is not the tool for the job. You can rewrite the file using echo but you can't really edit it. Can you explain why you want to use echo in this way?
Evo2.
PS. Best use "want to" instead of "wanna". It's not actually a word and comes across as whining - especially when used repeatedly.
IMHO, echo is not the tool for the job. You can rewrite the file using echo but you can't really edit it. Can you explain why you want to use echo in this way?
Evo2.
PS. Best use "want to" instead of "wanna". It's not actually a word and comes across as whining - especially when used repeatedly.
Actually i wanna write post script in kickstart file and there i wanna edit ntp.conf file and wanna write our ntp server ip in server directive and i wanna comment other server directive. how this can be achived using post script in kickstart?
To answer the original question, yes it is possible to edit a file using nothing more than the shell's builtin read and echo commands together with the shell's ability to test and modify variables. At its most basic:
Code:
IFS=
while read -r Line; do
case "$Line" in
"server ipaddress")
echo "server otheripaddress";;
*)
echo "$Line";;
esac
done <file >file.new
while read -r Line; do
echo "$Line"
done <file.new >file
I actually had to do something like that a long time ago in a SunOS standalone shell when a bad /etc/fstab left me with nothing but shell builtins to work with.
To answer the original question, yes it is possible to edit a file using nothing more than the shell's builtin read and echo commands together with the shell's ability to test and modify variables. At its most basic:
Code:
IFS=
while read -r Line; do
case "$Line" in
"server ipaddress")
echo "server otheripaddress";;
*)
echo "$Line";;
esac
done <file >file.new
while read -r Line; do
echo "$Line"
done <file.new >file
I actually had to do something like that a long time ago in a SunOS standalone shell when a bad /etc/fstab left me with nothing but shell builtins to work with.
Thanks for giving the answer of my original question even i marked it as solved.
you have written a good script but i am not good at writing these kind of scripts. could you please gimme a link from where i can learn about this. because i am not able to understand most of the things in the script.
Many posters here do not have English as their native language. They do their best to communicate using English, and usually better than most native English speakers would do in another language. Disparaging the English usage of posters is not, IMO, a good thing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.