- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed question
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
02-06-2001 06:48 PM
02-06-2001 06:48 PM
I believe sed can do this but I cant figure out how to get it to work. Any ideas would be appreciated.
thanks John
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 07:52 PM
02-06-2001 07:52 PM
Re: sed question
Your task can be accomplished easily with perl:
==
[root@cc0070 /root]# cat infile
abc
History
def
History abcdef abcdef
abc
abc
a History a b c d e
b History a b c d e
[root@cc0070 /root]# ./testperl
[root@cc0070 /root]# cat outfile
abc
History
INSERTED_TEXT
def
History abcdef abcdef
INSERTED_TEXT
abc
abc
a History a b c d e
b History a b c d e
You have new mail in /var/spool/mail/root
[root@cc0070 /root]# cat testperl
#!/usr/bin/perl
open (INFILE, "infile");
open (OUTFILE, ">outfile");
while (
{
$_ =~s/^History(.*)/History\1\nINSERTED_TEXT/g;
print OUTFILE $_;
}
==
Hope this helps. Regards.
Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 07:53 PM
02-06-2001 07:53 PM
Re: sed question
To add 3 lines after all lines that begin with History:
sed -e '/^History/aline to add #1line to add #2line to add #3' file
Note the single quotes and the backslashes \. They are important.
If you have multiple History lines and only want to append after the first, it gets more complex and requires two sed commands (at least by me - sed gurus may be able to do it in one command).
sed -e '/^History/aline to add #1line to add #2line to add #3' -e '/^History/d' file > file.tmp
sed -e '1,/^History/d' file >> file.tmp
Disclaimer: I read the HP man pages but tested this on a Linux box. It *should* work on HP-UX.
--Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 08:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2001 01:05 AM
02-07-2001 01:05 AM
Re: sed question
#!/usr/bin/ksh
cat - << EOF | ed -s file_to_edit
/History
+1
i
New Line of text
.
w
q
EOF