- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- System Administration
- >
- insert # in the begining of a line in which the re...
-
- Forums
-
Blogs
- Alliances
- Around the Storage Block
- Behind the scenes @ Labs
- HPE Careers
- HPE Storage Tech Insiders
- Infrastructure Insights
- Inspiring Progress
- Internet of Things (IoT)
- My Learning Certification
- OEM Solutions
- Servers: The Right Compute
- Shifting to Software-Defined
- Telecom IQ
- Transforming IT
- Infrastructure Solutions German
- L’Avenir de l’IT
- IT e Trasformazione Digitale
- Enterprise Topics
- ИТ для нового стиля бизнеса
- Blogs
-
Quick Links
- Community
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Contact
- Email us
- Tell us what you think
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Enterprise.nxt
- Marketplace
- Aruba Airheads Community
-
Forums
-
Blogs
-
InformationEnglish
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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.
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2019 Hewlett Packard Enterprise Development LP