473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to change the content of textfile dynamically

THIS IS THE TEXT FILE.................................


SERVER put_hostname_here ANY No Key 2007
VENDOR netcool 3773


MY REQUIREMENT IS IT HAS TO CHANGE TO

SERVER 192.18.28.36 ANY No Key 73744
VENDOR netcool 8389



FOR NUMBER OF FILES

PLS GIVE ME THE SOLUTION OR SCRIPTS FOR THIS
Nov 29 '07 #1
5 1347
eWish
971 Expert 512MB
Welcome to TSDN.

We are here to assist others who need help with code that they have written. Please post your code so that we may do the same for you. Here a couple of great resources for those learning Perl.

Learning Perl
perldoc

Regards,

Kevin
Nov 29 '07 #2
numberwhun
3,509 Expert Mod 2GB
Welcome to TSDN.

We are here to assist others who need help with code that they have written. Please post your code so that we may do the same for you. Here a couple of great resources for those learning Perl.

Learning Perl
perldoc

Regards,

Kevin
You can always read the online book, Beginning Perl as well.

Regards,

Jeff
Nov 29 '07 #3
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. ################################################################
  3. #SCRIPT FOR CHANNING THE THE LICENSE_HOSTNAME,PORT NUMBER AND VENDOR PORT IN THE LICENSE FILE
  4. ################################################################
  5.  
  6. my $dirtoget="/export/home/guru/workspace/test/etc";
  7.  
  8. ##########################
  9. #FUNCTION TO SET THE LICENSE_HOSTNAME
  10. ###########################
  11.  
  12. sub sethost
  13. {
  14.                         my $file = shift;
  15.                     open(THISFILE, "< $dirtoget/$file");
  16.                         my @lines = <THISFILE>;
  17.                         close(THISFILE);
  18.                         my $hostname = "172.18.20.53";
  19. foreach my $item(@lines)
  20.          {
  21.                            my $match = "SERVER";
  22.                                if(substr($item,0, length($match)) =~/$match/)
  23.                                            {
  24.                                       my @field = split(/ /,$item);
  25.                                           $field[1] = $hostname;
  26.                                   substr($item,0,length($item)) = "" ;
  27.                                           $item = $field[0]." " . $field[1]." ".$field[2]." ".$field[3].$field[4];
  28.                                            }
  29.          }
  30. open(OUTPUT, ">  $dirtoget/$file");
  31. print OUTPUT  @lines;
  32. close(OUTPUT);
  33. }
  34.  
  35. #############################
  36. #FUNCTION TO SET THE LICENSE_PORT_NUMBER
  37. #############################
  38.  
  39. sub setport
  40. {
  41.                      my $file = shift;
  42.                      open(THISFILE, "< $dirtoget/$file");
  43.                      my @lines = <THISFILE>;
  44.                      close(THISFILE);
  45.                      my $portname = "0786";
  46.  foreach my $item(@lines)
  47.  {
  48.                 #print $item;
  49.                          my $match = "ANY";
  50.                               if($item=~/$match/)
  51.                                    {
  52.                                    my @field = split(/$match/,$item);
  53.                                    # substr($item,0,length($item)) ="";
  54.                                    $item = $field[0].$match." ".$portname."\n";
  55.                                }
  56.  }
  57. open(OUTPUT, ">  $dirtoget/$file");
  58. print OUTPUT  @lines;
  59. close(OUTPUT);
  60.  
  61. ############################
  62. #FUNCTION TO SET THE VENDOR_PORT_NUMBER
  63. #############################
  64.  
  65. sub setvendorport
  66. {
  67.                 my $file = shift;
  68.                         open(THISFILE, "< $dirtoget/$file");
  69.                         my @lines = <THISFILE>;
  70.                         close(THISFILE);
  71.                         my $vendorportname = "7860";
  72. foreach my $item(@lines)
  73. {
  74.                    my $match = "VENDOR";
  75.                                 if($item=~/$match/)
  76.                            {
  77.                                 my @field = split(/ /,$item);
  78.                                 $field[2] = $vendorportname ;
  79.                                # substr($item,0,length($item)) ="";
  80.                             $item = $field[0]." " .$field[1]." ".$field[2]."\n";#." ".$field[4];
  81.                             }
  82. }
  83. open(OUTPUT, ">  $dirtoget/$file");
  84. print OUTPUT  @lines;
  85. close(OUTPUT);
  86. }
  87.  
  88. ########################################################
  89. #TO OPEN A DIRECTORY AND READ THE CONTENT OF THE DIRECTORY
  90. ########################################################
  91.  
  92. opendir(FILEHANDLE, $dirtoget) || die("Cannot open directory");
  93. @lines= readdir(FILEHANDLE);
  94. closedir(FILEHANDLE);
  95. #print "@lines  ";
  96. foreach my $file (@lines)
  97. {
  98.  
  99.         if($file =~ /.lic/)
  100.         {
  101.                  sethost($file);
  102.                  setport($file);
  103.                  setvendorport($file);
  104.                  #print $file . "\n";
  105.              }
  106. }
Nov 30 '07 #4
KevinADC
4,059 Expert 2GB
Judging by the code, I'd say you're not a perl programmer.
Nov 30 '07 #5
Judging by the code, I'd say you're not a perl programmer.

hello sir,


pls send me a code to change the content of text file dynamically.



thank you
Dec 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Hans A | last post by:
I have a textfile "textfile.txt" containing a list of words. There is one word on each line. I want to pick two random lines from this textfile, and I have tried to do something like: //Loading...
10
by: TheKeith | last post by:
I don't know much about javascript, so take it easy on me. Is there a way to dynamically change a CSS layers dimensions on the fly. Here is what I'm doing. I have a bunch of thumbnails that when...
1
by: Amir Eshterayeh | last post by:
Dear Friends I need to change the css file of my aspx files dynamically so users can choose their css file names and when page loads, it read css file name from database. I try to use...
4
by: michael | last post by:
I have an html text string within a div, eg.: <div id="example">Text text text</div> I know its easy to change styles by using getElementById - for example: ...
2
by: Amir Eshterayeh | last post by:
Dear Friends I want to change the name of my css file dynamically so as Mr. Jos Branders helped me, I can change the <head> tag into an HTML control like this: <head id="myhead" runat="server">...
0
by: G.Esmeijer | last post by:
Friends, I have have filled a datagrid (flexgrid from C1Components) with the content of a textfile. Now I would like to save the content to an access table. I've tried the insert command I have...
16
by: Phil Hey | last post by:
Hi, I can change the icon for a folder by right clicking on it > going to the customize tab > and selecting Choose Picture. Does anyone know if it is possible to do this programmatically...
9
by: ad | last post by:
Hi, How can I dynamically change the MasterPager of a web page?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.