- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Need help with scripting mass file edits..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 08:59 AM
тАО08-14-2007 08:59 AM
I am wanting to know a way to shell (ksh)script-edit a file by having a script that searches for a specific string, and then inputs lines after that specific string. Please help, as I will be up all night if I can't figure this out.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 09:46 AM
тАО08-14-2007 09:46 AM
Re: Need help with scripting mass file edits..
I am going to assume that you want to preserve the entire contents of the line on which your match occurs, and simply add some number of lines thereafter.
This script will do that for any number of files *and* update them "in-place":
By example, using 'localhost' as a string to be matched (e.g. as with '/etc/hosts'):
# perl -pi.old -e 's/(localhost.*)/$1\nnew\nlines\nhere/' file1 file2 file3
The original file will be preserved with an ".old" suffix and the file updated in-place.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 10:41 AM
тАО08-14-2007 10:41 AM
Re: Need help with scripting mass file edits..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 10:52 AM
тАО08-14-2007 10:52 AM
Re: Need help with scripting mass file edits..
> Perhaps I should have stated that I wanted to input lines of text after the string that is being searched out.
OK, and do what with any text that follows the match on the line?
This discards any text on the line on which the pattern matches and inserts new test lines thereafter:
# perl -pi.old -e 's/(localhost)/$1\nnew\nlines\nhere/' file1 file2 file3 ...
Change the pattern in parentheses to anything you want.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 11:23 AM
тАО08-14-2007 11:23 AM
Re: Need help with scripting mass file edits..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 11:37 AM
тАО08-14-2007 11:37 AM
Solution> I would want to keep the text on that line, but I guess a solution would be to let that text be discarded, and re-add it in the replacement text.
OK, solution-1 retains it. Solution-2 discards it and this one (solution-3) pushes text that trails the matched pattern to its own line and then inserts the line(s) you specify:
# perl -pi.old -e 's/(localhost)(.*)/$1\n$2\nnew\nlines\nhere/' file1 file2 file3 ...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 11:58 AM
тАО08-14-2007 11:58 AM
Re: Need help with scripting mass file edits..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 12:06 PM
тАО08-14-2007 12:06 PM
Re: Need help with scripting mass file edits..
Cmnd_Alias EPROV_ADMIN_CMDS = /usr/sbin/groupadd, /usr/sbin/groupdel, /usr/sbin/groupmod, \
/usr/bin/last, /usr/bin/listusers, /usr/sbin/logins, \
/usr/sbin/usermod, /usr/sbin/useradd, /usr/sbin/userdel, \
/usr/bin/passwd, /usr/bin/ypmatch, /usr/bin/yppasswd, \
/usr/sbin/ypcat, /usr/bin/login
Is there a way to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 12:19 PM
тАО08-14-2007 12:19 PM
Re: Need help with scripting mass file edits..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 06:03 PM
тАО08-14-2007 06:03 PM
Re: Need help with scripting mass file edits..
job for him when he's getting paid for it
and I'm not, but if you expect someone else
to do it for you, you might consider
precisely and accurately specifying the work
you want done. In this case, one way to do
that might be to show an example of what the
file would look like before and after the
change(s) you'd like to make.
When a reply begins, "I am going to assume",
then _you_ can assume that you didn't specify
the problem clearly enough.