Script to edit file




















For eg: below is what I have in the config file "configfile. How to edit txt file by shell script? What I want to do is just delete some lines from a text file, I know it's easy using copy and redirect function, but what I have to do is edit this file delete the lines directly, as new lines may be added to the text file during this period.

Can AIX do this? RedHat Commands. OpenSolaris Commands. Linux Commands. SunOS Commands. FreeBSD Commands. Full Man Repository. Advanced Search. Contact Us. Forum Rules. Mark Forums Read. Thread Tools. View Public Profile for tiger Find all posts by tiger This is the most reliable method i though of when editing files without nay risk of breaking any conf.

Can anyone suggest a better code. Another thing I need to modify a line in a conf but i don't remember what is the whole of text to replaced. Specify an in-place editing option -i if you want makes the backup with. Now i want use sed to do the following 1. If the priority key already exists, it will set its value, otherwise it will add a priority entry after the last entry in the section.

You might also want to check out Augeas , tool for programmatically modifying config files. It is very powerful in combination with Puppet a configuration management system , but can also be used by itself. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more. Edit a file via bash script Ask Question. Asked 9 years, 4 months ago. Active 9 years, 4 months ago. Viewed 21k times. Since there is no do-done, while will execute only the first sal. I updated your script accordingly. There is only one change - in the sal command in the while loop. Otherwise, your scripts seems correct. Just use "hi this is cool " in place of "www.

Make the change in both the sen and sal commands. Your reply. Ask a question. I can't echo to a new file and enter in my date since this file will be copied from a server-specific file. That's the easiest way. This assumes that all lines that contains a date to replace also are the only lines to start with 'Current date'. Means all lines starting with: Current date and ending in anything. Double " are used around the sed statement so that variables will be used as variables, not strings.

The inode number of the edited file remains unchanged. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more.



0コメント

  • 1000 / 1000