473,405 Members | 2,421 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,405 software developers and data experts.

How to parse this file?

Hi,

I have only been learning Perl for less than 2 weeks. I am a C++ programmer.
I have attached a portion of the data below. The data is in file1.txt. I would like to move the data from file1.txt to file2.txt. But, I only want to keep the numbers.

Eg: I want row 1 to look like this:

1 1549367 11 8 3 11 0 -12.00 6.00 -0.25 -3.00 0.00 -1.67 -12.00 6.00 -0.64

Instead of this:

1 Chr26 1549367 11 GGGGGGGAAGA 8 3 Transition 11 0 -12.00 6.00 -0.25 -3.00 0.00 -1.67 -12.00 6.00 -0.64

This is what I have done so far (file1.txt will be in @ARGV):
Expand|Select|Wrap|Line Numbers
  1. open FILE2, "+>file2.txt" or die "Cant not open file2.txt!";
  2. my $line;
  3. while($line = readline(ARGV))
  4. {
  5.         print FILE2 $line;
  6. }
  7.  
The code above only copies content of file1.txt (ARGV) into file2.txt.
I tried to use ‘seek’ and ‘tell()’ but, to solve my problem above but, I got confused :(

I also tried this:

Expand|Select|Wrap|Line Numbers
  1. Open(FILE, “file1.txt”)
  2. @theFile = <FILE>;
  3.  
This puts every row in the array @the File. But, I can I now modify the elements of one row? (I’m still a novice Perl programmer)

Thank you for your help

/………………………………………………………………………………………../
The file portion

1 Chr26 1549367 11 GGGGGGGAAGA 8 3 Transition 11 0 -12.00 6.00 -0.25 -3.00 0.00 -1.67 -12.00 6.00 -0.64
1 Chr26 1549501 15 ccCctctccccctCC 12 3 Transition 3 12 -17.00 6.00 0.50 1.00 6.00 2.67 -17.00 6.00 0.93
1 Chr26 1549552 14 AagAAaaAAAagga 11 3 Transition 6 8 -31.00 6.00 -2.09 -12.00 3.00 -5.67 -31.00 6.00 -2.86
1 Chr26 1549563 14 tAAaaAAAattat^Ft 9 5 Transversion 5 9 -7.00 6.00 0.22 -64.00 4.00 -18.40 -64.00 6.00 -6.43
1 Chr26 1549726 14 TtTtctTtTtTTTT 13 1 Transition 8 6 -3.00 6.00 1.92 6.00 6.00 6.00 -3.00 6.00 2.21
2 Chr26 1549737 16 T+1Atttt+1aT+1At+1aTt+1aT+1AT+1AT+1AT+1AtT+1A^FA 15 11 Transversion 16 10 -64.00 6.00 -35.67 -64.00 6.00 -46.18 -64.00 6.00 -40.12
2 Chr26 1549815 9 CtCTTTTTT 7 2 Transition 8 1 -3.00 6.00 -0.14 -9.00 0.00 -4.50 -9.00 6.00 -1.11
1 Chr26 1549914 12 gGGGGGGGAGgg 11 1 Transition 9 3 -9.00 6.00 1.18 -4.00 -4.00 -4.00 -9.00 6.00 0.75
1 Chr26 1550018
Oct 19 '11 #1
2 1519
numberwhun
3,509 Expert Mod 2GB
So, what you basically want to do is take each line individually from @ARGV, and then parse each line, character by character, outputting all of each line, minus the letters.

I don't have any working code at the moment, but that is my take on it.

Regards,

Jeff
Oct 20 '11 #2
RonB
589 Expert Mod 512MB
Jeff FYI, this question is cross posted on perlguru.
Oct 20 '11 #3

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

Similar topics

1
by: Harobed | last post by:
Hi, I have a xml file encode in ISO-8859-15. When xml.dom parse this file, it send this error : xml.parsers.expat.ExpatError: not well-formed (invalid token): line 9, column 46 Line 9 content...
2
by: Anthony Liu | last post by:
I copy-pasted the following sample xml document from http://slis-two.lis.fsu.edu/~xml/sample.html and saved it as samplexml.xml. Please note that I removed the following line <!DOCTYPE...
19
by: Peter A. Schott | last post by:
I've got a file that seems to come across more like a dictionary from what I can tell. Something like the following format: ###,1,val_1,2,val_2,3,val_3,5,val_5,10,val_10...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
3
by: IWP506 | last post by:
Hey, I have a lot of common things I want to be included on different pages (i.e. the page title, the header, some buttons and such, etc.). So I was thinking of putting things like...
2
by: Lou Civitella | last post by:
Using VB.Net what is the best way to parse a file name from a web address? For example: http://www.website.com/downloads/video1.avi I want to extract video1.avi from the above address. ...
7
by: amfr | last post by:
I was wondering how i could parse the contents of a file into an array. the file would look something like this: gif:image/gif html:text/html jpg:image/jpeg .... As you can see, it contains...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.