HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- insert text between lines
Operating System - Linux
1827319
Members
4745
Online
109961
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
01-20-2011 05:32 PM
01-20-2011 05:32 PM
insert text between lines
Hi there
I need to know how to insert a text into existing file, just before certain text.
Example:
echo "my text" >> myfile.conf
cat myfile.conf
line 1
line 2
my text
#
# AMAVISD-NEW
#
Regards
Peter
I need to know how to insert a text into existing file, just before certain text.
Example:
echo "my text" >> myfile.conf
cat myfile.conf
line 1
line 2
my text
#
# AMAVISD-NEW
#
Regards
Peter
Jesus is the King
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2011 08:49 PM
01-20-2011 08:49 PM
Re: insert text between lines
Not a very useful description of what you
wish to do. Should "my text" be added at the
beginning of an existing line? On a new line
of its own? Is "my text" always only one
line of text (a constant or variable), or
might it be the contents of some other file?
What is the "certain text" in this "Example"?
Is it the whole line, or some part of a line?
"sed" can do some useful things. For
example:
dyi # cat text.txt
abc def
ghi jkl
mno pqr
stu vwx
dyi # sed -n -e '1,/hi/p' text.txt
abc def
ghi jkl
dyi # sed -n -e '1,/hi/d' -e p text.txt
mno pqr
stu vwx
man sed
wish to do. Should "my text" be added at the
beginning of an existing line? On a new line
of its own? Is "my text" always only one
line of text (a constant or variable), or
might it be the contents of some other file?
What is the "certain text" in this "Example"?
Is it the whole line, or some part of a line?
"sed" can do some useful things. For
example:
dyi # cat text.txt
abc def
ghi jkl
mno pqr
stu vwx
dyi # sed -n -e '1,/hi/p' text.txt
abc def
ghi jkl
dyi # sed -n -e '1,/hi/d' -e p text.txt
mno pqr
stu vwx
man sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2011 10:10 PM
01-20-2011 10:10 PM
Re: insert text between lines
Should "my text" be added at the
beginning of an existing line?
Yes,just before:
#
# AMAVISD-NEW
#
Is "my text" always only one
line of text (a constant or variable), or
might it be the contents of some other file?
It's just one line - constant.
beginning of an existing line?
Yes,just before:
#
# AMAVISD-NEW
#
Is "my text" always only one
line of text (a constant or variable), or
might it be the contents of some other file?
It's just one line - constant.
Jesus is the King
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2011 10:12 PM
01-20-2011 10:12 PM
Re: insert text between lines
Hello.
You can use 'sed', namely the 'i\' and 'a\' (GNU extensions) commands.
Regards,
Goran
You can use 'sed', namely the 'i\' and 'a\' (GNU extensions) commands.
Regards,
Goran
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP