Sponsored Content
Top Forums Shell Programming and Scripting Splitting text string with "|" pipe delimiters Post 302426823 by alanp36 on Thursday 3rd of June 2010 04:37:03 AM
Old 06-03-2010
Thanks for the replies amitranjansahu, frans and Scrutinizer.

amitranjansahu, I saw yours first, and tried it. That works perfectly, thanks.

frans and Scrutinizer, thanks for the alternative methods. Very interesting - I will save those for possible future situations.

You guys are great Smilie. Cheers, Alan.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies

2. Shell Programming and Scripting

get string out of text file after "= "

I have a text file like: The name of the project = "Symbion centrifuge" The name of the subsytem = "motor demon" now i would like to read the string after the = into a variable to write it to another file. later use like: sed s/'PROJECTNAME'/"$projectname"/ <header.tex >temp ... (9 Replies)
Discussion started by: vivelafete
9 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

sort text having delimiter with "|" (pipe)

i am having text file below NARGU S S 12358 SALES REP |22| Acccount/s RAJU R B 64253 SALES REP |12| Acccount/s RUKMAN S 32588 SALES REP |10| Acccount/s NARGUND S S 12356... (3 Replies)
Discussion started by: suryanarayana
3 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

8. Shell Programming and Scripting

Need HELP with AWK split. Need to check for "special characters" in string before splitting the file

Hi Experts. I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file. awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename sample data 1,abc,def,1234,A * 2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies

9. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

10. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies
Moose::Manual::Delegation(3)				User Contributed Perl Documentation			      Moose::Manual::Delegation(3)

NAME
Moose::Manual::Delegation - Attribute delegation VERSION
version 2.0604 WHAT IS DELEGATION
? Delegation is a feature that lets you create "proxy" methods that do nothing more than call some other method on an attribute. This lets you simplify a complex set of "has-a" relationships and present a single unified API from one class. With delegation, consumers of a class don't need to know about all the objects it contains, reducing the amount of API they need to learn. Delegations are defined as a mapping between one or more methods provided by the "real" class (the delegatee), and a set of corresponding methods in the delegating class. The delegating class can re-use the method names provided by the delegatee or provide its own names. Delegation is also a great way to wrap an existing class, especially a non-Moose class or one that is somehow hard (or impossible) to subclass. DEFINING A MAPPING
Moose offers a number of options for defining a delegation's mapping, ranging from simple to complex. The simplest form is to simply specify a list of methods: package Website; use Moose; has 'uri' => ( is => 'ro', isa => 'URI', handles => [qw( host path )], ); With this definition, we can call "$website->host" and it "just works". Under the hood, Moose will call "$website->uri->host" for you. Note that $website is not automatically passed to the "host" method; the invocant is "$website->uri". We can also define a mapping as a hash reference. This allows you to rename methods as part of the mapping: package Website; use Moose; has 'uri' => ( is => 'ro', isa => 'URI', handles => { hostname => 'host', path => 'path', }, ); In this example, we've created a "$website->hostname" method, rather than using "URI.pm"'s name, "host". These two mapping forms are the ones you will use most often. The remaining methods are a bit more complex. has 'uri' => ( is => 'ro', isa => 'URI', handles => qr/^(?:host|path|query.*)/, ); This is similar to the array version, except it uses the regex to match against all the methods provided by the delegatee. In order for this to work, you must provide an "isa" parameter for the attribute, and it must be a class. Moose uses this to introspect the delegatee class and determine what methods it provides. You can use a role name as the value of "handles": has 'uri' => ( is => 'ro', isa => 'URI', handles => 'HasURI', ); Moose will introspect the role to determine what methods it provides and create a mapping for each of those methods. Finally, you can also provide a sub reference to generate a mapping. You probably won't need this version often (if ever). See the Moose docs for more details on exactly how this works. NATIVE DELEGATION
Native delegations allow you to delegate to standard Perl data structures as if they were objects. has 'queue' => ( traits => ['Array'], isa => 'ArrayRef[Item]', default => sub { [ ] }, handles => { add_item => 'push', next_item => 'shift', }, ) The "Array" trait in the "traits" parameter tells Moose that you would like to use the set of Array helpers. Moose will then create "add_item" and "next_item" methods that "just work". Behind the scenes "add_item" is something like sub add_item { my ($self, @items) = @_; for my $item (@items) { $Item_TC->validate($item); } push @{ $self->queue }, @items; } Moose includes the following traits for native delegation: o Array o Bool o Code o Counter o Hash o Number o String CURRYING
Currying allows you to create a method with some pre-set parameters. You can create a curried delegation method: package Spider; use Moose; has request => ( is => 'ro' isa => 'HTTP::Request', handles => { set_user_agent => [ header => 'UserAgent' ], }, ) With this definition, calling "$spider->set_user_agent('MyClient')" will call "$spider->request->header('UserAgent', 'MyClient')" behind the scenes. Note that with currying, the currying always starts with the first parameter to a method ($_[0]). Any arguments you pass to the delegation come after the curried arguments. MISSING ATTRIBUTES
It is perfectly valid to delegate methods to an attribute which is not required or can be undefined. When a delegated method is called, Moose will throw a runtime error if the attribute does not contain an object. 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::Manual::Delegation(3)
All times are GMT -4. The time now is 05:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy