- 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
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2006 07:22 PM
07-27-2006 07:22 PM
Re: Another Inquiry
Please see attched script and some raw file. This also includes the file that needs to be inserted.
In the script, i have changed/replaced the /^Product Name,XXX/YY$/ to /^Diffusion Lot ID,NA$/ (Kindly check the raw data) because the Diffusion Lot ID is more fixed.
Thanks and hoping to hear from you soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2006 07:23 PM
07-27-2006 07:23 PM
Re: Another Inquiry
Please see attached script and some raw file (zipped format). This also includes the file that needs to be inserted (integ) to the 3 file with TDF extension.
In the script, i have changed/replaced the /^Product Name,XXX/YY$/ to /^Diffusion Lot ID,NA$/ (Kindly check the raw data) because the Diffusion Lot ID is more fixed.
Thanks and hoping to hear from you soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2006 08:26 PM
07-27-2006 08:26 PM
Solutiona short one to test:
File content before:
cat /tmp/x
aa
bb
cc
aa
dd
gg
Running the command
perl -i -e 'while (<>) { if($f) {print "xx\nyy\n";$f=0;} print; chomp; if ($_ eq "aa") { $f=1} }' /tmp/x
results in
cat /tmp/x
aa
xx
yy
bb
cc
aa
xx
yy
dd
gg
Perhaps this is enough - just change the conditions for inserting as needed.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2006 08:55 PM
07-27-2006 08:55 PM
Re: Another Inquiry
just 2 suggestions:
1. writing the subject line clearly will give good fast response and while searching it will help a lot.
2. submit points to those who helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 02:27 AM
07-28-2006 02:27 AM
Re: Another Inquiry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 02:49 AM
07-28-2006 02:49 AM
Re: Another Inquiry
If you want to update the file "in-place" while creating a backup copy with the extension '.old', use this variation of my script.
# cat inserter
#!/usr/bin/perl -i.old
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
No output occurs to your terminal. You can 'cat' the modified file when done. As noted, the original file is preserved as 'file.old' where 'file' is whatever filename you specified.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2006 03:24 AM
07-28-2006 03:24 AM
Re: Another Inquiry
This forum is really great!