- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: insert # in the begining of a line in which th...
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
тАО03-12-2009 10:22 PM
тАО03-12-2009 10:22 PM
Hi Experts,
It is required to insert # in the begining of a line in which the a particular word exists. I don't want to create a new file then replace the original file.
For example, I just want to comment the following line in /etc/fstab
/dev/vg00/lvol7 /usr vxfs delaylog 0 2
Using sed or any other command can I acheive this?
Creating a new file and copying it back is possible. Is there any other method?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2009 10:46 PM
тАО03-12-2009 10:46 PM
Re: insert # in the begining of a line in which the required word exists.
sed '\:/dev/vg00/lvol7:s/^/#/' /etc/fstab > /etc/fstab.new
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 12:25 AM
тАО03-13-2009 12:25 AM
Re: insert # in the begining of a line in which the required word exists.
sed -i "s/^\(\/dev\/vg00\/lvol7.*\)$/#\1/" /etc/fstab
where \/dev\/vg00\/lvol7 is the search pattern.
Remember to escape / since sed see it as a delimiter between search and replace patterns.
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 12:40 AM
тАО03-13-2009 12:40 AM
Re: insert # in the begining of a line in which the required word exists.
Its a good practics to make a backup of file.
cp -p /etc/fstab /etc/fstab.org
awk '{print "#"$0 }'/etc/fstab
using sed
please see the examples given in below link
http://sed.sourceforge.net/sed1line.txt
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 12:41 AM
тАО03-13-2009 12:41 AM
Re: insert # in the begining of a line in which the required word exists.
I don't like to create a new file. I would like to make changes in the file itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 12:44 AM
тАО03-13-2009 12:44 AM
Re: insert # in the begining of a line in which the required word exists.
I get error " sed: illegal option -- i". OS is Hp-UX 11.23
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 01:06 AM
тАО03-13-2009 01:06 AM
SolutionI suppose you could use ex:
ex <
wq
EOF
>Fredrik: You can use the -i syntax for sed
This isn't valid for HP-UX's sed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 01:45 AM
тАО03-13-2009 01:45 AM
Re: insert # in the begining of a line in which the required word exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 01:55 AM
тАО03-13-2009 01:55 AM
Re: insert # in the begining of a line in which the required word exists.
I would try out one of the awk or perl hacks that was written above.
please assign 0 points for this one :)
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2009 03:05 AM
тАО03-13-2009 03:05 AM
Re: insert # in the begining of a line in which the required word exists.
Dennis,
Your answer is met my expectation. It worked fine.
Fredrik: Assigned 2 points for immediate acknowledgement of mistakes.