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.
Now I want to write a bash script that replaces the 12 for test01 to 14. Is it possible to write such a script with bash? Could anyone give me an example command? And how can I remove for example the line which contains test07 from the script using bash.. Is this possible to do that from the CLI? Any help would be great!!
Only because I'm feeling nice today, I won't say you should 'man sed'
> more change-it.sh
#!/bin/sh
for i in `ls $.net`
do
sed -e 's/604800/666666' \
-e 's/384000/333333' $i > blah.tmp
mv blah.tmp $i
done
That'll do what you want for multiple files and multiple changes, I leave it as an exercise to the reader how to do what he wants with what he has to do.
And how can I remove for example the line which contains test07 from the script using bash.. Is this possible to do that from the CLI? Any help would be great!!
You could use sed -i option to edit file in place also, like
Code:
# replaces the XX for testXX to XX
sed -i -re 's/(testXX)(:.*)/\1:XX/' /home/file
# remove the line which contains testXX
sed -i -e 's/testXX.*//' /home/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.