Sponsored Content
Full Discussion: extract numbers from a word
Top Forums Shell Programming and Scripting extract numbers from a word Post 302068653 by Ygor on Monday 20th of March 2006 05:40:53 AM
Old 03-20-2006
Try...
Code:
echo "abcd.123.xyz" | tr -dc '[0-9]'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract numbers below words with awk

Hi all, Please some help over here. I have a Sales.txt file containing info in blocks for every sold product in the pattern showed below (only for 2 products). NEW BLOCK SALE DATA PRODUCT SERIAL 79833269999 146701011945004 .Some other data .Some... (17 Replies)
Discussion started by: cgkmal
17 Replies

2. Shell Programming and Scripting

BASH. Need to extract some numbers and take the average

Hey all, I ran some simulations, of which the output is 100s of files. I've used grep to extract the vital information needed from the files. This has made my task somewhat easier. But I still need to perform some mathematical calculations (average and geometrical average) on the results of the... (9 Replies)
Discussion started by: slackjack
9 Replies

3. Shell Programming and Scripting

awk fetch numbers after the word

Hi, I would want to fetch all the numbers after a word the number of characters could very. how can I do that? below is the example of the data and the expected output sample data 03 xxxx occurs 1090 times. 04 aslkja occurs 10 times. I would want to fetch 10 & 1090 separately. (13 Replies)
Discussion started by: ahmedwaseem2000
13 Replies

4. Shell Programming and Scripting

find the last word with all numbers?

Hi, I was trying to extract the last word with all numbers using awk. like the below example. I am looking for a pattern using awk. desired result: (13 Replies)
Discussion started by: hitmansilentass
13 Replies

5. UNIX for Dummies Questions & Answers

Extract numbers from .txt file

I need to extract all the p-value numbers and the rho numbers from a .txt file and write them as coma separated values in a new file. Ideally I would get two files in the end, one for p- values and one for rho. Any suggestions? I appreciate your help!!! The .txt file looks essentially like this... (5 Replies)
Discussion started by: eggali
5 Replies

6. Shell Programming and Scripting

Summing numbers after specific word

Hi all, Looking for suggestions on a better way to sum numbers in a key value pair formated file. What I have works but seems really clunky to me. Any suggestions would be greatly appreciated. cat test.txt | perl -ne 'm/(M=)(\d+\.?\d?\d?)/ && print "$2\n"' | awk '{ sum+=$1} END {printf... (7 Replies)
Discussion started by: cgol
7 Replies

7. Shell Programming and Scripting

extract whole thing in word, leaving behind last word. - perl

Hi, i've a string /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD/TESi T_11_HD_120/hd-12 i need to get string, like /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD the words from HD should get deleted, i need only a string till HD, i dont want to use any built in... (4 Replies)
Discussion started by: asak
4 Replies

8. Shell Programming and Scripting

Put numbers after word

Hello I have an file with this content -------------------------------------------- timer one timer two timer three timer four timer five timer six timer seven ------------------------------------------- And I want the following output.... (4 Replies)
Discussion started by: thailand
4 Replies

9. Shell Programming and Scripting

Extract numbers from file name-how to ?

Hello friends,I am new to Unix programming. how do I achieve the following in Unix shell script (I am running ksh on AIX) extract the number from name of file? My file format is like "LongFileName-1234.020614-221030.txt" now I want to extract value which is between (-) hyphen and (.) dot... (4 Replies)
Discussion started by: f150
4 Replies

10. UNIX for Beginners Questions & Answers

Substr with % - extract numbers only

# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.5 (Maipo) I have this script that will monitor filesystems and send me e-amil alerts. #! /bin/ksh DIST_LIST=monitor@...com WORKDIR=/home/monitor WARNLEVEL=90 MAIL_SUBJ="filesystems monitor on "$(hostname) ... (3 Replies)
Discussion started by: danielshell
3 Replies
Hash::AsObject(3pm)					User Contributed Perl Documentation				       Hash::AsObject(3pm)

NAME
Hash::AsObject - treat hashes as objects, with arbitrary accessors/mutators SYNOPSIS
$h = Hash::AsObject->new; $h->foo(123); print $h->foo; # prints 123 print $h->{'foo'}; # prints 123 $h->{'bar'}{'baz'} = 456; print $h->bar->baz; # prints 456 DESCRIPTION
A Hash::AsObject is a blessed hash that provides read-write access to its elements using accessors. (Actually, they're both accessors and mutators.) It's designed to act as much like a plain hash as possible; this means, for example, that you can use methods like "DESTROY" to get or set hash elements with that name. See below for more information. METHODS
The whole point of this module is to provide arbitrary methods. For the most part, these are defined at runtime by a specially written "AUTOLOAD" function. In order to behave properly in all cases, however, a number of special methods and functions must be supported. Some of these are defined while others are simply emulated in AUTOLOAD. new $h = Hash::AsObject->new; $h = Hash::AsObject->new(\%some_hash); $h = Hash::AsObject->new(%some_other_hash); Create a new Hash::AsObject. If called as an instance method, this accesses a hash element 'new': $h->{'new'} = 123; $h->new; # 123 $h->new(456); # 456 isa This method cannot be used to access a hash element 'isa', because Hash::AsObject doesn't attempt to handle it specially. can Similarly, this can't be used to access a hash element 'can'. AUTOLOAD $h->{'AUTOLOAD'} = 'abc'; $h->AUTOLOAD; # 'abc' $h->AUTOLOAD('xyz') # 'xyz' Hash::AsObject::AUTOLOAD recognizes when AUTOLOAD is begin called as an instance method, and treats this as an attempt to get or set the 'AUTOLOAD' hash element. DESTROY $h->{'DESTROY'} = []; $h->DESTROY; # [] $h->DESTROY({}) # {} "DESTROY" is called automatically by the Perl runtime when an object goes out of scope. A Hash::AsObject can't distinguish this from a call to access the element $h->{'DESTROY'}, and so it blithely gets (or sets) the hash's 'DESTROY' element; this isn't a problem, since the Perl interpreter discards any value that DESTROY returns when called automatically. VERSION When called as a class method, this returns $Hash::AsObject::VERSION; when called as an instance method, it gets or sets the hash element 'VERSION'; import Since Hash::AsObject doesn't export any symbols, this method has no special significance and you can safely call it as a method to get or set an 'import' element. When called as a class method, nothing happens. The methods "can()" and "isa()" are special, because they're defined in the "UNIVERSAL" class that all packages automatically inherit from. Unfortunately, this means that you can't use Hash::AsObject to access elements 'can' and 'isa'. CAVEATS
No distinction is made between non-existent elements and those that are present but undefined. Furthermore, there's no way to delete an element without resorting to "delete $h->{'foo'}". Storing a hash directly into an element of a Hash::AsObject instance has the effect of blessing that hash into Hash::AsObject. For example, the following code: my $h = Hash::AsObject->new; my $foo = { 'bar' => 1, 'baz' => 2 }; print ref($foo), " "; $h->foo($foo); print ref($foo), " "; Produces the following output: HASH Hash::AsObject I could fix this, but then code like the following would throw an exception, because "$h->foo($foo)" will return a plain hash reference, not an object: $h->foo($foo)->bar; Well, I can make "$h->foo($foo)->bar" work, but then code like this won't have the desired effect: my $foo = { 'bar' => 123 }; $h->foo($foo); $h->foo->bar(456); print $foo->{'bar'}; # prints 123 print $h->foo->bar; # prints 456 I suppose I could fix that, but that's an awful lot of work for little apparent benefit. Let me know if you have any thoughts on this. BUGS
Autovivification is probably not emulated correctly. The blessing of hashes stored in a Hash::AsObject might be considered a bug. Or a feature; it depends on your point of view. TO DO
o Add the capability to delete elements, perhaps like this: use Hash::AsObject 'deleter' => 'kill'; $h = Hash::AsObject->new({'one' => 1, 'two' => 2}); kill $h, 'one'; That might seem to violate the prohibition against exporting functions from object-oriented packages, but then technically it wouldn't be exporting it from anywhere since the function would be constructed by hand. Alternatively, it could work like this: use Hash::AsObject 'deleter' => 'kill'; $h = Hash::AsObject->new({'one' => 1, 'two' => 2}); $h->kill('one'); But, again, what if the hash contained an element named 'kill'? o Define multiple classes in "Hash/AsObject.pm"? For example, there could be one package for read-only access to a hash, one for hashes that throw exceptions when accessors for non-existent keys are called, etc. But this is hard to do fully without (a) altering the underlying hash, or (b) defining methods besides AUTOLOAD. Hmmm... VERSION
0.06 AUTHOR
Paul Hoffman <nkuitse AT cpan DOT org> CREDITS
Andy Wardley for Template::Stash, which was my inspiration. Writing template code like this: [% foo.bar.baz(qux) %] Made me yearn to write Perl code like this: foo->bar->baz($qux); COPYRIGHT
Copyright 2003-2007 Paul M. Hoffman. All rights reserved. This program is free software; you can redistribute it and modify it under the same terms as Perl itself. perl v5.10.1 2010-04-24 Hash::AsObject(3pm)
All times are GMT -4. The time now is 05:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy