473,396 Members | 1,714 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,396 software developers and data experts.

editing data file

Hi,
I am trying to write a perl script that will read a three-column data file and write certain lines of it in to a new data file according the ranges of values that each of these lines contain. For example, if the file looks like this:

c11 c12 c13
c21 c22 c23
...

I want to be able to select all rows j that have cj1, cj2, and cj3 within certain respective ranges.

I've attempted to do so, but I'm having trouble defining an array in terms of each column numbers. The following is what I have concocted so far from putting random pieces together, but I am missing the overall picture. Any help would be much appreciated.

#!/usr/bin/perl -w

open(INPUT, "<INPUT");
open(OUTPUT, ">OUTPUT");

@data = <INPUT>;

read(INPUT, @data($a, $b, $c));

while ( $a < '5' && $b < '5' && $c < '5')
{
print OUTPUT;
}
close(INPUT);
close(OUTPUT);
Feb 9 '07 #1
2 1406
Hi,

I think you should use an array of arrays for dealing with that kind of data.
So, you could read the file in @data (which will be a two dimensional array) like this:
Expand|Select|Wrap|Line Numbers
  1. my @data;
  2. my $i=0;
  3. while (<INPUT>){
  4.   $data[$i++]=[split];
  5. }
  6.  
the processing is easy then:
Expand|Select|Wrap|Line Numbers
  1. for my $row(@data){
  2.   my ($a,$b,$c)=@{$row};
  3.   if ($a < '5' && $b < '5' && $c < '5'){
  4.       print OUTPUT "$a $b $c\n";
  5.   }
  6. }
  7.  
Feb 9 '07 #2
KevinADC
4,059 Expert 2GB
another suggestion:

Expand|Select|Wrap|Line Numbers
  1. open(INPUT, "<INPUT");
  2. open(OUTPUT, ">OUTPUT");
  3. while(<INPUT>){
  4.    my ($v1, $v2, $v3) = /^\D+(\d+)\s+\D+(\d+)\s+\D+(\d+)/;
  5.    print OUTPUT if ( $v1 < 5 && $v2 < 5 && $v3 < 5);
  6. }
  7. close(INPUT);
  8. close(OUTPUT);
Feb 9 '07 #3

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

Similar topics

4
by: Jerry Khoo | last post by:
i am currently working on an assignment that requires the program to manage the files like editing file content, modifying file content, and deleting file contents. My question is what sort of...
1
by: pratyush.aditya | last post by:
hi, can anybody tell me what are the steps and procedures that are to be taken for video editing like frame extraction etc from avi,mpeg files using C programming.
8
by: Sam Collett | last post by:
Is there a basic guide on Xml document creation and editing (simpler than the MSDN docs). Say I want to create a file containing the following: <?xml version="1.0" encoding="utf-8"...
12
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty...
8
by: D | last post by:
Hi, I currently have a Python app with a Tkinter GUI frontend that I use for system administration. Everytime it launches, it reads a text file which contains info about each host I wish to...
2
by: ritesh | last post by:
Hi, I'm facing a problem in which I need to edit an already created file, and the editing needs to be done at the start of the file rather then appending to the file. OS - Linux,Solaris ...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
5
by: Tim Mackey | last post by:
hi, i have put my web.sitemap in /App_Data so i can edit it programatically via a web admin page, inheriting the modify permissions from the App_Data folder etc. i was hoping the provider would...
10
by: Ikolder | last post by:
Hello, I hope someone can help me with this! I have a problem editing a text file my file looks like this 11 13 15 16 23
0
by: ee0jmt | last post by:
Hopefully an easy question: Using vb.net I have opened an xml file (which is encrypted) retreived the file information as a string, carry out some editing of the xml data. I now want to produce a...
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
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...
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.