473,469 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

To delete first few letters in a string in a file

12 New Member
I have got a file called filelist with content
Expand|Select|Wrap|Line Numbers
  1. f+    f    templatedata\poc\Ravi\Appfolder\filelist.xml    
  2. f+    f    templatedata\poc\Ravi\Appfolder\testdeploy.xml    
  3. f    -    templatedata\poc\Ravi\Appfolder\testdeploy2.xml    
  4. f    -    templatedata\poc\Ravi\Webfolder\apples.bmp    
  5.  
I need to remove the first few characters in the begining and need to have only
Expand|Select|Wrap|Line Numbers
  1.  
  2. templatedata\poc\Ravi\Appfolder\filelist.xml
  3. templatedata\poc\Ravi\Appfolder\testdeploy.xml
  4. templatedata\poc\Ravi\Appfolder\testdeploy2.xml
  5. templatedata\poc\Ravi\Webfolder\apples.bmp
  6.  
so that i can compare the files and write the appfolder and webfolder contents to different files...but because of these unwanted characters f+ f ,I am not able to compare,.........how to remove these unwanted letters from the begining

My code for comparing is as follows
Expand|Select|Wrap|Line Numbers
  1. open (MyFileHandle,"<C\:\\home\\filelist.txt") or die("File Not Found\n");
  2. open (MyWebFileHandle,">C\:\\home\\Weblist.txt") or die("File Open Error");
  3. open (MyAppFileHandle,">C\:\\home\\Weblist.txt") or die("File Open Error");
  4.  
  5. until((eof(MyFileHandle)) && (seek(MyFileHandle,0,0) != eof(MyFileHandle)))
  6. {
  7.  
  8.     $Text = readline(MyFileHandle);
  9.     if(defined($Text)) 
  10.     {
  11.         if ($Text=~/^templatedata\\poc\\Ravi\\Appfolder/) 
  12.         {
  13.          print MyAppFileHandle $Text;
  14.          print MyAppFileHandle "\n";
  15.         }
  16.         elsif ($Text=~/^templatedata\\poc\\Ravi\\Webfolder/)
  17.         {
  18.         print MyWebFileHandle $Text;
  19.         print MyWebFileHandle "\n";
  20.         }
  21.             }
  22. }
  23.  
Mar 12 '08 #1
1 1576
numberwhun
3,509 Recognized Expert Moderator Specialist
I have not tested your code, but I went a completely different route and chose to use the split function, which is part of Perl. Here is what I tried that works:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $field1;
  5. my $field2;
  6. my $field3;
  7.  
  8. open(FILE, "<data.txt") or die "Cannot open data.txt:  $!";
  9. open(FILE2, ">newdata.txt") or die "Cannot oen newdata.txt: $!";
  10.  
  11. while(<FILE>)
  12. {
  13.     ($field1, $field2, $field3) = split(/\s+/, $_);
  14.     print FILE2 ("$field3\n");
  15. }
  16.  
  17.  
  18. close(FILE);
  19. clost(FILE2);
  20.  
Also, when you place text or code in the forums, please be sure to enclose it in code tags as I have done to your original post. This makes for better readability.

Regards,

Jeff
Mar 12 '08 #2

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

Similar topics

2
by: Edward K. Ream | last post by:
From the documentation for the string module at: C:\Python23\Doc\Python-Docs-2.3.1\lib\module-string.html letters: The concatenation of the strings lowercase and uppercase described below....
0
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
12
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files...
3
by: richardkreidl | last post by:
I have the following module that I delete old files based on how old they are: Sub Main() Dim First_Date As String = Date.Today.AddDays(-7) Dim Archive_Files() As String =...
3
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >>...
22
by: Cylix | last post by:
I have a 4row x 1col table, I would like to drop all the content of row three. Since Mac IE5.2 does not suppport deleteRow method, I have also try to set the innerHTML=''; but it does not work. ...
9
by: Laphan | last post by:
Hi All I'm using the below to limit the input into a text box to just letters, numbers, hyphens and full stops, but I also need to allow the backspace, delete and arrow keys to come through. ...
7
by: ITAutobot25 | last post by:
My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI...
2
by: whodgson | last post by:
The following code accepts a string from the user and swaps the first and last letters in each word. It prints out the original string incorrectly by dropping off the first letter of the first word....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.