- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script or sed/awk command to grep pattern and appe...
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
Forums
Discussions
Discussions
Discussions
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
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
05-09-2005 08:30 AM
05-09-2005 08:30 AM
1) grep for a pattern in a line beginning with (for instance : DS)
2) Comment out that line (for instance : #DS)
3) and append another line right after after it (for instance: DSabc.domain.com
Basically modify /etc/mail/sendmail.cf file using a one line sed command or some script:
See below
==========================
###DS
DSmyname.domain.com
======================
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2005 08:42 AM
05-09-2005 08:42 AM
Re: script or sed/awk command to grep pattern and append line after it ?
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2005 09:14 AM
05-09-2005 09:14 AM
Solution$cat x
DS
xDS
DSx
$
$perl -pi -e 'if (/^(DS)/) { print "#$1\n"; chop; $_ .="abc.domain.com\n"}' x
$
$cat x
#DS
DSabc.domain.com
xDS
#DS
DSxabc.domain.com
In this example one liner you only have to specify you select string once and it remembers and use it (in $1 and $_)
The data example includes a 'false' match to make you think about how you want to handle those cases.
To latch onto just the search string on a line use: /^(DS)$/
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2005 09:15 AM
05-09-2005 09:15 AM
Re: script or sed/awk command to grep pattern and append line after it ?
Thanks. But now my file only has many lines with just:
DSabc.domain.com
DSabc.domain.com
DSabc.domain.com
...
..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2005 09:19 AM
05-09-2005 09:19 AM
Re: script or sed/awk command to grep pattern and append line after it ?
You may have what I am looking for as I did a quick test. I will give it a shot tom. as I have to leave. But Thanks a bunch. I will post results tom.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2005 09:35 AM
05-09-2005 09:35 AM
Re: script or sed/awk command to grep pattern and append line after it ?
Here is how I do it without perl
# sed -e "1,\$s/^DS/#DS/" /etc/mail/sendmail.cf > /tmp/sm.cf
# cat /tmp/sm.cf > /etc/mail/sendmail.cf
this way, you do not mess up your file permissions for sendmail.cf
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2005 01:29 AM
05-10-2005 01:29 AM
Re: script or sed/awk command to grep pattern and append line after it ?
out the line (what I wanted) but does not append abc.domain.com to
the the end of next line. (See #3 in my question above).
DSabc.domain.com. Thanks.
Hein, Very Very close to what I wanted. Your script commented out just #DS or $1 and ignored the rest of the line. But again,
I admit I did not explain correctly exactly what I wanted otherwise you would have given me the exact answer and thus you deserve full points.
Below is what I used which was just tweaking your command a little bit. Thanks Hein.
perl -pi -e 'if (/^(DS)/) { print "#$_\n"; chop; $_ .="abc.domain.com\n"}' /etc/mail/sendmail.cf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2005 01:30 AM
05-10-2005 01:30 AM