HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- append multiple lines of text at begining of a exi...
Operating System - HP-UX
1833056
Members
2590
Online
110049
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
04-08-2008 07:22 AM
04-08-2008 07:22 AM
append multiple lines of text at begining of a existing file
how can I append multiple lines of text at begining of a existing file.
I can use awk 'BEGIN { print "line1} {print}' file.org >> file.new.
Outcome:
line1
line2
existing text
I can use awk 'BEGIN { print "line1} {print}' file.org >> file.new.
Outcome:
line1
line2
existing text
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2008 07:45 AM
04-08-2008 07:45 AM
Re: append multiple lines of text at begining of a existing file
You can do something as simple as this:
echo line1 > file.new
echo line2 >> file.new
cat file.orig >> file.new
mv file.new file.orig
Pete
Pete
echo line1 > file.new
echo line2 >> file.new
cat file.orig >> file.new
mv file.new file.orig
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2008 07:50 AM
04-08-2008 07:50 AM
Re: append multiple lines of text at begining of a existing file
>> how can I append multiple lines of text at begining of a existing file.
You can not, not directly.
You'll need to stash the lines from the existign files, or use an intermediate file.
To give but a simple example:
$ cat x y > y
cat: Cannot use y as both input and output.
'solution'
$ cat x y > z
$ mv z y
Here is a silly PERL solution which SLURPs the input files, then BURPs the output.
perl -e '$a = do { local( @ARGV, $/)=shift;<>}; $out=shift; $b = do { local( @ARGV, $/)=$out;<>}; open $fh,">$out"; print $fh $a.$b' x y'
Remember, beauty is in the eye of the beholder
The 'local $/' undefines the line terminator making the whole file a piece of string.
http://www.perl.com/pub/a/2003/11/21/slurp.html
hth,
Hein.
You can not, not directly.
You'll need to stash the lines from the existign files, or use an intermediate file.
To give but a simple example:
$ cat x y > y
cat: Cannot use y as both input and output.
'solution'
$ cat x y > z
$ mv z y
Here is a silly PERL solution which SLURPs the input files, then BURPs the output.
perl -e '$a = do { local( @ARGV, $/)=shift;<>}; $out=shift; $b = do { local( @ARGV, $/)=$out;<>}; open $fh,">$out"; print $fh $a.$b' x y'
Remember, beauty is in the eye of the beholder
The 'local $/' undefines the line terminator making the whole file a piece of string.
http://www.perl.com/pub/a/2003/11/21/slurp.html
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2008 07:59 AM
04-08-2008 07:59 AM
Re: append multiple lines of text at begining of a existing file
na
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
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP