07-15-2011
From list to csv
Hello,
i have a file with this row:
item1
attribute1 item1
attribute2 item1
attribute3 item1
item2
attribute1 item2
attribute2 item2
attribute3 item2
.....
itemn
attribute1 itemn
attribute2 itemn
attribute3 itemn
I would change in a new file so:
item1,attribute1 item1,attribute2 item1,attribute3 item1
...
itemn,attribute1 itemn,attribute2 itemn,attribute3 itemn
i tried with s/\n/,/g to insert comma, but how can i group item in same row?
Thanks
Bye
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all,
I have a huge csv file with the following format of data,
Num SNPs, 549997
Total SNPs,555352
Num Samples, 157
SNP, SampleID, Allele1, Allele2
A001,AB1,A,A
A002,AB1,A,A
A003,AB1,A,A
...
...
...
I would like to write out a list of unique SNP (column 1). Could you... (3 Replies)
Discussion started by: phoeberunner
3 Replies
2. Shell Programming and Scripting
Hi,
I create on script for controlM, what need to call the csv file. But I have 100 files. I would like to have one txt file how call all file.
So I create one scrip a.sh for the controlM. When I called the file xxx.csv, it work fine. but when I created one b.txt with
xxx.csv
yyy.csv... (1 Reply)
Discussion started by: santana
1 Replies
3. Shell Programming and Scripting
Hi Fellows,
I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem:
I have csv files in the following pipe-delimited format:
Column1|Column2|Column3|Column4|NEWLINE
Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies
4. Shell Programming and Scripting
Hi All,
Random question, how would you convert a data file from a list like so:
12345
12346
12347
12348
12349
12350
... <snip 100+ lines> ...
to comma separated X columns across:
12345,12346,12347
12348,12349,12350
Why would you want to do this? The background to this is a... (2 Replies)
Discussion started by: craigp84
2 Replies
5. Shell Programming and Scripting
I need to take the second column of a .csv file and count the number of instances of each unique value in that same second column. I'd like the output to be value,count sorted by most instances. Thanks for any guidance!
Data example:
317476,317756,0
816063,318861,0
313123,319091,0... (4 Replies)
Discussion started by: batcho
4 Replies
6. Shell Programming and Scripting
Hi
I have two csv files, with the following formats:
FileA.log:
Application, This occured blah
Application, That occured blah
Application, Also this
AnotherLog, Bob did this
AnotherLog, Dave did that
FileB.log:
Uk, London, Application, datetime, LaterDateTime, Today it had'nt... (8 Replies)
Discussion started by: PerlNewbRP
8 Replies
7. Shell Programming and Scripting
Hi experts,
I have a very large (1.5M lines), sorted but unstructured list that looks like this:
process_nameA valueA
process_nameA valueA
...
process_nameB valueB
process_nameB valueB
...
process_nameN valueN
I'd like to turn this into a csv.
The values are all... (4 Replies)
Discussion started by: abercrom
4 Replies
8. Shell Programming and Scripting
I have a CSV with below values
name,city,2,country
name,city,15,country
abc,wq,10,afdfd,
qeqe,ewqre,1,wqew
I need to sort them in ascending order based on the value of column 3 and then , pick the rows with values less than 10 and be able to display the columns in that row. Can anyone... (11 Replies)
Discussion started by: Nevergivup
11 Replies
9. Shell Programming and Scripting
Hi,
I have a file of csv data, which looks like this:
file1:
1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628
2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies
10. Shell Programming and Scripting
Hi All,
I am looking for some help to convert a csv with IP ranges in.. in the format e.g.
1.1.1.2, 1.1.1.5
2.1.1.10, 2.1.1.20
and would be looking to output as follows:
1.1.1.2
1.1.1.3
1.1.1.4
1.1.1.5
2.1.1.10
2.1.1.11
etc etc up to 2.1.1.20
I have tried a few google... (4 Replies)
Discussion started by: zippyzip
4 Replies
LEARN ABOUT DEBIAN
class::gomor::array
Class::Gomor::Array(3pm) User Contributed Perl Documentation Class::Gomor::Array(3pm)
NAME
Class::Gomor::Array - class and object builder, array version
SYNPOSIS
# Create a base class in BaseClass.pm
package My::BaseClass;
require Class::Gomor::Array;
our @ISA = qw(Class::Gomor::Array);
our @AS = qw(attribute1 attribute2);
our @AA = qw(attribute3 attribute4);
our @AO = qw(other);
# You should initialize yourself array attributes
sub new { shift->SUPER::new(attribute3 => [], attribute4 => [], @_) }
# Create indices and accessors
My::BaseClass->cgBuildIndices;
My::BaseClass->cgBuildAccessorsScalar(@AS);
My::BaseClass->cgBuildAccessorsArray(@AA);
sub other {
my $self = shift;
@_ ? $self->[$self->cgGetIndice('other')] = [ split(/
/, shift) ]
: @{$self->[$self->cgGetIndice('other')]};
}
1;
# Create a subclass in SubClass.pm
package My::SubClass;
require My::BaseClass;
our @ISA = qw(My::BaseClass);
our @AS = qw(subclassAttribute);
My::SubClass->cgBuildIndices;
My::SubClass->cgBuildAccessorsScalar(@AS);
sub new {
shift->SUPER::new(
attribute1 => 'val1',
attribute2 => 'val2',
attribute3 => [ 'val3', ],
attribute4 => [ 'val4', ],
other => [ 'none', ],
subclassAttribute => 'subVal',
);
}
1;
# A program using those classes
my $new = My::SubClass->new;
my $val1 = $new->attribute1;
my @values3 = $new->attribute3;
my @otherOld = $new->other;
$new->other("str1
str2
str3");
my @otherNew = $new->other;
print "@otherNew
";
$new->attribute2('newValue');
$new->attribute4([ 'newVal1', 'newVal2', ]);
DESCRIPTION
This class is a subclass from Class::Gomor. It implements objects as array references, and inherits methods from Class::Gomor.
GLOBAL VARIABLES
See Class::Gomor.
METHODS
new (hash)
Object constructor. This is where user passed attributes (hash argument) are checked against valid attributes (gathered by
cgGetAttributes method). Valid attributes are those that exists (doh!), and have not an undef value. The default is to check this, you
can avoid it by setting $NoCheck global variable (see perldoc Class::Gomor).
cgBuildIndices
You MUST call this method one time at the beginning of your classes, and all subclasses (even if you do not add new attributes). It
will build the matching between object attributes and their indices inside the array object. Global variables will be created in your
class, with the following format: $__attributeName.
cgBuildAccessorsScalar (array ref)
cgBuildAccessorsArray (array ref)
See Class::Gomor.
cgGetIndice (scalar)
Returns the array indice of specified attribute passed as a parameter. You can use it in your programs to avoid calling directly the
global variable giving indice information concerning requesting object, thus avoiding using `no strict 'vars';'. This method is usually
used when you build your own accessors (those using attributes defined in @AO).
cgClone [ (scalar) ]
You can clone one of your objects by calling this method. An optional parameter may be used to create multiple clones. Cloning will
occure only on the first level attributes, that is, if you have attributes containing other objects, they will not be cloned.
cgFullClone [ (scalar) ]
This method is the same as cgClone, but will clone all attributes recursively, but only if they are subclassed from Class::Gomor. So,
objects created with other modules than Class::Gomor::Array or Class::Gomor::Hash will not be cloned.
Another thing to note, there is no catch for cycling references (when you link two objects with each others). You have been warned.
cgDumper
Will return a string as with Data::Dumper Dumper method. This is useful for debugging purposes, because an arrayref object does not
include attributes names.
SEE ALSO
Class::Gomor
AUTHOR
Patrice <GomoR> Auffret
COPYRIGHT AND LICENSE
Copyright (c) 2004-2009, Patrice <GomoR> Auffret
You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.
perl v5.10.1 2009-05-23 Class::Gomor::Array(3pm)