Hi,
i am new to awk. I am using csv2pipe script(shown below)
BEGIN { FS=SUBSEP; OFS="|" }
{
result = setcsv($0, ",")
print
}
# setcsv(str, sep) - parse CSV (MS specification) input
# str, the string to be parsed. (Most likely $0.)
# sep, the separator between the values.
#
#... (6 Replies)
Hi,
I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format.
Example:
File.txt
AP|{SSHA}VEEg42CNCghUnGhCVg==
APVG3|{SSHA}XK|"password"
AP3|{SSHA}XK|"This is test"
....
etc
---------
test.sh has... (1 Reply)
Hi All,
I am hoping someone can help me with some scripting I need to complete using AWK.
I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format.
The Input file is:-
aaaa bbbbb ccccc 1 xxxx aaa bbb
aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
I have file which contains gene lines something like this
Transcript Name GO
POPTR_0016s06290.1 98654
POPTR_2158s00200.1 11324
POPTR_0004s22390.1 12897
POPTR_0001s11490.1
POPTR_0016s13950.1 14532
POPTR_0015s05840.1 13455
POPTR_0013s06470.1 12344... (6 Replies)
Hello,
I couldn't find anything on the Forum that would help me to solve this problem. Could any body help me process below data using awk?
I have got two files:
file1:
Worker1: Thomas
Position: Manager
Department: Sales
Salary: $5,000
Worker2: Jason
Position: ... (5 Replies)
I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this?
... (12 Replies)
I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but
- Currently, script is not printing lines to File3.txt in order.
Thanks a lot.
Any help is appreciated.
Script I am using:
awk 'FNR == NR && ! /^]*$/ {... (9 Replies)
Hi,
I want to compare a value from test file and redirect the o/p value to the same file
input file
250 32000 32 128
Below is my code
awk '{ if ($1 < "300") print $1 > /tmp/test}' test
want to compare 250 < 300 then print 300 to the same place
below is the... (24 Replies)
The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format:
input
chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18
chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
LEARN ABOUT DEBIAN
moose::cookbook::basics::person_buildargsandbuild
Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD(3pm) User Contributed Perl Documentation Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD(3pm)NAME
Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD - Using BUILDARGS and BUILD to hook into object construction
VERSION
version 2.0603
SYNOPSIS
package Person;
has 'ssn' => (
is => 'ro',
isa => 'Str',
predicate => 'has_ssn',
);
has 'country_of_residence' => (
is => 'ro',
isa => 'Str',
default => 'usa'
);
has 'first_name' => (
is => 'ro',
isa => 'Str',
);
has 'last_name' => (
is => 'ro',
isa => 'Str',
);
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
if ( @_ == 1 && ! ref $_[0] ) {
return $class->$orig(ssn => $_[0]);
}
else {
return $class->$orig(@_);
}
};
sub BUILD {
my $self = shift;
if ( $self->country_of_residence eq 'usa' ) {
die 'Cannot create a Person who lives in the USA without an ssn.'
unless $self->has_ssn;
}
}
DESCRIPTION
This recipe demonstrates the use of "BUILDARGS" and "BUILD". By defining these methods, we can hook into the object construction process
without overriding "new".
The "BUILDARGS" method is called before an object has been created. It is called as a class method, and receives all of the parameters
passed to the "new" method. It is expected to do something with these arguments and return a hash reference. The keys of the hash must be
attribute "init_arg"s.
The primary purpose of "BUILDARGS" is to allow a class to accept something other than named arguments. In the case of our "Person" class,
we are allowing it to be called with a single argument, a social security number:
my $person = Person->new('123-45-6789');
The key part of our "BUILDARGS" is this conditional:
if ( @_ == 1 && ! ref $_[0] ) {
return $class->$orig(ssn => $_[0]);
}
By default, Moose constructors accept a list of key-value pairs, or a hash reference. We need to make sure that $_[0] is not a reference
before assuming it is a social security number.
We call the original "BUILDARGS" method to handle all the other cases. You should always do this in your own "BUILDARGS" methods, since
Moose::Object provides its own "BUILDARGS" method that handles hash references and a list of key-value pairs.
The "BUILD" method is called after the object is constructed, but before it is returned to the caller. The "BUILD" method provides an
opportunity to check the object state as a whole. This is a good place to put logic that cannot be expressed as a type constraint on a
single attribute.
In the "Person" class, we need to check the relationship between two attributes, "ssn" and "country_of_residence". We throw an exception if
the object is not logically consistent.
MORE CONSIDERATIONS
This recipe is made significantly simpler because all of the attributes are read-only. If the "country_of_residence" attribute were
settable, we would need to check that a Person had an "ssn" if the new country was "usa". This could be done with a "before" modifier.
CONCLUSION
We have repeatedly discouraged overriding "new" in Moose classes. This recipe shows how you can use "BUILDARGS" and "BUILD" to hook into
object construction without overriding "new".
The "BUILDARGS" method lets us expand on Moose's built-in parameter handling for constructors. The "BUILD" method lets us implement logical
constraints across the whole object after it is created.
AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for
details.
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc..
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.14.2 2012-06-28 Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD(3pm)