- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Another Inquiry
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-26-2006 06:10 PM
тАО07-26-2006 06:10 PM
Another inquiry on file manipulation....
I have a file (more than 10000+) and i need to insert the following line with it.
Program Name,XXXXX
Program Version,YYYYYY
Stage,1
My file currently contains the following info:
...
Product Name, XXX/YY
Operator,1234
...
I need to insert between the Product Name and Operator the following:
Program Name,XXXXX
Program Version,YYYYYY
Stage,1
Such that my file will look like this:
...
Product Name, XXX/YY
Program Name,XXXXX
Program Version,YYYYYY
Stage,1
Operator,1234
...
Maximum point to all correct replies.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2006 06:48 PM
тАО07-26-2006 06:48 PM
Re: Another Inquiry
Product Name, $X/$Y
Program Name,$X
Program Version,$Y
Stage,1
Do you need to copy the above $X and $Y strings to the inserted lines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2006 07:43 PM
тАО07-26-2006 07:43 PM
Re: Another Inquiry
Hi Dennis,
The 3 lines are fixed at the moment. or I was thinking of putting it in a file (3 lines) and merge it with the file provided that my file content will still look like this.
...
...
Product Name, XXX/YY
Program Name,XXXXX
Program Version,YYYYYY
Stage,1
Operator,1234
...
...
On your inquiry.
Do you need to copy the above $X and $Y strings to the inserted lines? Yes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2006 09:21 PM
тАО07-26-2006 09:21 PM
Re: Another Inquiry
it's stiil not clear for me:
This result:
1)
Product Name, XXX/YY
Program Name,XXX
Program Version,YY
Stage,1
Operator,1234
or that:
2)
Product Name, XXX/YY
Program Name,ZZZZZ
Program Version,TTTTTT
Stage,1
Operator,1234
A solution will severely depend on that.
mfg Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2006 08:56 AM
тАО07-27-2006 08:56 AM
Re: Another Inquiry
The output should be:
Product Name,XXX/YY
Program Name,ZZZZZ
Program Version,TTTTTT
Stage,1
Operator,1234
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2006 09:30 AM
тАО07-27-2006 09:30 AM
Re: Another Inquiry
If I understand correctly, this should do what you ask:
# cat inserter
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
print;
if (m/^Product Name/) {
print "Program Name,ZZZZZ\n";
print "Program Version,TTTTTT\n";
print "Stage,1\n";
}
}
...run as:
# ./inserter file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2006 11:10 AM
тАО07-27-2006 11:10 AM
Re: Another Inquiry
# cat f1
...
Product Name, XXX/YY
Operator,1234
...
# cat f2
Program Name,XXXXX
Program Version,YYYYYY
Stage,1
use this ex construct...
# ex -s +'/^Product Name, XXX\/YY$/r f2 | wq' f1
- Tags:
- ex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2006 02:57 PM
тАО07-27-2006 02:57 PM
Re: Another Inquiry
I've tested your script and the result does not change the file though the output at the screen is the right one. I need to change the file also just as the output at the screen.
Also, I can call the perl script you made from any other script, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2006 03:01 PM
тАО07-27-2006 03:01 PM
Re: Another Inquiry
Sorry for the confusion. I have files (10000+) that needs to be change. I have tested the ex command and it actually, outputted the way i wanted to. But when i put it inside my script,
it ask for a key?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2006 05:11 PM
тАО07-27-2006 05:11 PM
Re: Another Inquiry
I put the ex command inside a script too and it runs fine doesn't ask for a key. Could you attach your script here so it can be looked at. Also if you need to process 10000+ files simply put the ex command inside a for-loop i.e.
#!/usr/bin/sh
for i in $(ls -1
do
ex -s +'/^Product Name, XXX\/YY$/r insertfile | wq' $i
done
- Tags:
- for loop