Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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 want to edit a crontab file with the help echo command.
we are using a tool called HP Opsware
opsware is a GUI tool which connects to UNIX servers with root permissions.
here my query is just assume i have a file called test.txt
here i want to comment the 9th line, i mean put a hash on 9th line with the help of echo command.
host1#cat -n test
cat -n test
1 This is a test file
2 This is a test file
3 This is a test file
4 This is a test file
5 This is a test file
6 This is a test guava
7 This is a test apple
8 This is a test mango
9 This is a test orange
10 This is a test anar.
I can able to comment the 9th line, but its not making changes in the original file
$sed '9s/^/#/' test
This is a test apple
This is a test banana
This is a test orange
This is a test apple
This is a test apple
This is a test apple
This is a test apple
This is a test apple
#This is a test apple
This is a test apple
orly$cat test
This is a test apple
This is a test banana
This is a test orange
This is a test apple
This is a test apple
This is a test apple
This is a test apple
This is a test apple
This is a test apple
This is a test apple
I redirected the output to another file, it would be great if it make changes to original file..sed '9s/^/#/' test > test1
orly$sed '9s/^/#/' test > test1
1 This is a test apple
2 This is a test banana
3 This is a test orange
4 This is a test apple
5 This is a test apple
6 This is a test apple
7 This is a test apple
8 This is a test apple
9 #This is a test apple
10 This is a test apple
For the record, the vast majority of command line tools are unable to alter the original input, and only print the modified results to stdout. You must use a temporary file in most cases.
Even the -i option above is just an extension added to the gnu version of sed, and not available in other implementations. And all it does is use a temporary file in the background anyway.
If you really want to do script-based direct editing of files, check out ed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.