- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Replace whole line using sed or awk
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
тАО07-30-2003 10:06 PM
тАО07-30-2003 10:06 PM
I need to replace an entire line that contains a certain string with another line.
Does anyone know how I could do this? If awk or sed are not the best tools to do this I am open to suggestions.
Sorry if I am duplicating, but I have been reading man pages and trawling the posts on this website for the last 2 hours.
Cheers
Ross
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2003 10:15 PM
тАО07-30-2003 10:15 PM
Re: Replace whole line using sed or awk
$ sed 's /string/new string/g' old_filename >new_filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2003 10:18 PM
тАО07-30-2003 10:18 PM
Re: Replace whole line using sed or awk
Don't know if this is what you're after:
sed 's/
Then mv the newfile over the old.
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2003 10:25 PM
тАО07-30-2003 10:25 PM
Re: Replace whole line using sed or awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2003 10:29 PM
тАО07-30-2003 10:29 PM
Re: Replace whole line using sed or awk
For Example:
I have a file which sometimes contains this text.
quick brown fox
and sometimes contains
slow brown fox
I want to search for "brown" and then replace the entire line.
Any ideas?
Thanks
Ross
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2003 10:31 PM - last edited on тАО03-23-2017 03:06 AM by VidyaVI
тАО07-30-2003 10:31 PM - last edited on тАО03-23-2017 03:06 AM by VidyaVI
Re: Replace whole line using sed or awk
Have a look at this thread, it may helps:
https://community.hpe.com/t5/System-Administration/bd-p/itrc-156#.WNOdhE27odk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2003 10:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2003 11:33 PM
тАО07-31-2003 11:33 PM
Re: Replace whole line using sed or awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2003 01:41 AM
тАО08-01-2003 01:41 AM
Re: Replace whole line using sed or awk
Script on perl:
#!/usr/bin/perl
open (FD, "SRC_FILENAME");
open (FDN, ">TRGET_FILENAME");
foreach (
{
if (/STRING_FOR_REPLACE/)
{
print FDN "NEW_STRING_LINE";
}
else
{
print FDN "$_";
}
}
close (FDN);
close (FD);
#END
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2003 02:00 AM
тАО08-01-2003 02:00 AM
Re: Replace whole line using sed or awk
I should think this would do what I expect You to ask for.
If brown exist anyware in the input row, case independent, the whole input line is replaced by a new standard row.