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);
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: -
my @data;
-
my $i=0;
-
while (<INPUT>){
-
$data[$i++]=[split];
-
}
-
the processing is easy then: -
for my $row(@data){
-
my ($a,$b,$c)=@{$row};
-
if ($a < '5' && $b < '5' && $c < '5'){
-
print OUTPUT "$a $b $c\n";
-
}
-
}
-
another suggestion: - open(INPUT, "<INPUT");
-
open(OUTPUT, ">OUTPUT");
-
while(<INPUT>){
-
my ($v1, $v2, $v3) = /^\D+(\d+)\s+\D+(\d+)\s+\D+(\d+)/;
-
print OUTPUT if ( $v1 < 5 && $v2 < 5 && $v3 < 5);
-
}
-
close(INPUT);
-
close(OUTPUT);
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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.
|
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"...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |