Sponsored Content
Top Forums Shell Programming and Scripting awk if statement matching all lines starting w/ a number Post 302362025 by Arsenalman on Wednesday 14th of October 2009 06:44:55 PM
Old 10-14-2009
Usa usa usa !
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I get an if statement to execute based on number of lines in a file?

I need to have an if statement in a script to run if there are certain processes running. Easiest way I can see to do this is to run a ps and grep the results based on what I am looking for: $ ps -ef | grep wtrs --- webtrend 5046 1 0 May 12 ? 0:28 /webtrends/versions/6.1/wtrs_ui... (6 Replies)
Discussion started by: LordJezo
6 Replies

2. Shell Programming and Scripting

How to print the number of lines from a file, the starting string should be passed`

Hi , I have file, which has the below content: line 100 a b c d line300 a s d f s line200 a s d a (3 Replies)
Discussion started by: little_wonder
3 Replies

3. Shell Programming and Scripting

awk statement to match all lines starting with "#"

Looking for awk statement that will match all lines starting with "# " if ( $1 == \^"#" ) Input file: # of the server. If you would like to set these, please take out the # pound (#) sign in front of one or all severities and set it equal to # severity desired. For example, FATAL=3 #... (2 Replies)
Discussion started by: Arsenalman
2 Replies

4. Emergency UNIX and Linux Support

Urgent help pls.how to extract two lines having same starting number

Hi , I have a huge file like this =245 this is testing =035 abc123 =245 this is testing1 =035 abc124 =245 this is testing2 =035 abc125 =035 abc126 =245 this is testing3 here i have to pull out those lines having two =035 instead of alternative 035 and 245 i.e extract... (18 Replies)
Discussion started by: umapearl
18 Replies

5. Solaris

awk - Print variable number of colums from a starting column

Hi guys, I usualy am able to google awk stuff but I can't find it so far and there are so many awking gurus here that I will give it a shot. I want to print $1;$3;"$5 up to the $NF". In other words, I can have 1000 colums, but need to have $5 up to the end. I started with the idea of... (2 Replies)
Discussion started by: plmachiavel
2 Replies

6. Shell Programming and Scripting

Awk, sed - concatenate lines starting with string

I have a file that looks like this: John Smith http://www.profile1.com http://www.profile2.com http://www.profile3.com Marc Olsen http://www.profile4.com http://www.profile5.com http://www.profile6.com http://www.profile7.com Lynne Doe http://www.profile8.com http://www.profile9.com... (3 Replies)
Discussion started by: locoroco
3 Replies

7. Shell Programming and Scripting

Compare two files and count number of matching lines

Dear All, I would like to compare two files and return the number of matches found. Example File A Lx2 L1_Mus1 L1Md_T Lx5 L1M2 L1_Mus3 Lx3_Mus Lx9 Lx2A L1Md_A L1Md_F2 File B L1_Mus3 L1_Mus3 (3 Replies)
Discussion started by: paolo.kunder
3 Replies

8. Shell Programming and Scripting

Matching and Replacing file lines starting with $

Here is the task that I was presented with: I am dealing with about a 10,000 line input deck file for an analysis. About 10 separate blocks of around 25 lines of code each need to be updated in the input deck. The input deck (deckToChange in the code below) comes with 2 separate files. File 1... (5 Replies)
Discussion started by: tiktak292
5 Replies

9. Shell Programming and Scripting

Select only the lines of a file starting with a field which is matcing a list. awk?

Hello I have a large file1 which has many events like "2014010420" and following lines under each event that start with text . It has this form: 2014010420 num --- --- num .... NTE num num --- num... EFA num num --- num ... LASW num num --- num... (9 Replies)
Discussion started by: phaethon
9 Replies

10. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies
Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD(3)	User Contributed Perl Documentation   Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD(3)

NAME
Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD - Using BUILDARGS and BUILD to hook into object construction VERSION
version 2.0604 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.16.2 2012-09-19 Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD(3)
All times are GMT -4. The time now is 05:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy