Sponsored Content
Top Forums Shell Programming and Scripting SED command help: Can we pass predefined variables in place of regex Post 302300093 by usha rao on Monday 23rd of March 2009 08:04:10 AM
Old 03-23-2009
I have another problem with SED command.

i have a file which looks like this:
file1{
CPS: Error registering CPS with MBean Server -- this will NOT affect the normal functioning of the program -- CPS w
ill just not be available for dynamic reloading: java.lang.NoClassDefFoundError: javax/management/modelmbean/ModelM
BeanInfo

******* Command Response *******

CMD RESPONSE = tfwk15On:true
tfwk15FullyOn:true
}

here i want to get the final output as true for tfwk15FullyOn

my problem is
i am using a command like this:

cat file1 |sed 's/tfwk15FullyOn:/@/g' |awk -F"@" '{print $2}'| sed '/^$/d' | sed -e 's/^.*{\(.*\)},*/\1/'


with this command i need to get output as true

but instead i am getting as output which looks like

CPS: Error registering CPS with MBean Server -- this will NOT affect the normal functioning of the program -- CPS will just not be available for dynamic reloading: java.lang.NoClassDefFoundError: javax/management/modelmbean/ModelM
BeanInfo
true

whereas i want output as true only...
Is there something wrong with my sed usage??
also here i am using two sed command ,is there any way that it can be done with one sed command??

Thanks in advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

assigning variables in sed command

I need to assign a variable within a variable in a sed command. I tried doing the following in c shell. set left = 1 set right = 2 set segment = qwerty sed -n -e "/$segment{$left}/,/$segment{$right}/p" file.txt what is wrong with this syntax? (3 Replies)
Discussion started by: wxornot
3 Replies

2. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

3. Shell Programming and Scripting

Using SED command in a shell script: Unterminated address regex

Hi All, I am trying to use a sed command in a shell script in order to delete some lines in a file and I got the following error message. I don't understand why it is not working 'cause I have tried with simple quotes, then with double-quotes, and it is not working. sed: -e expression #1,... (7 Replies)
Discussion started by: Alpha3363
7 Replies

4. Shell Programming and Scripting

Place variables at the beginning of each line

Hello all, I am very new to the shell scripting and I hope someone can help me with this. I have thousands of files with certain format of information and I need to do this for all my files. For each file, grab the numbers in the first and second rows and place them in the position 1 and 2... (8 Replies)
Discussion started by: GoldenFire
8 Replies

5. Shell Programming and Scripting

Variables in SED command

Hi all, I want write a script to display 5rows at times from a input file. my out like: echo " display started" r1 r2 r3 r4 r5 ... Some action items... again i need next 5 lines. can you please advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

6. Shell Programming and Scripting

Place digit in front of the line searching pattern using sed command

hi All, i want to add the single digit front of the line in the report file and string compare with pattern file. patter file: pattern1.txt pattern num like 4 love 3 john 2 report file: report.txt i like very much but john is good boy i will love u so after execute... (9 Replies)
Discussion started by: krbala1985
9 Replies

7. UNIX for Dummies Questions & Answers

How to pass variables in Expect command?

Hi All, I need to frame a unix script to logon to a unix box. The credentials needs to be obtained from a property file on the same location. I am trying to use 'expect' and 'spawn' command to meet this req. When I am passing values, these commands are working fine. but when I am trying to... (3 Replies)
Discussion started by: mailkarthik
3 Replies

8. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

9. Shell Programming and Scripting

Need to pass value in sed command

Hi, I have a file a.xml containing the below <customerId>000</customerId> and a variable CUSTOMER_ID which is set to '333' Now I want to replace <customerId>000</customerId> with <customerId>333</customerId> by the below sed command and save the output in a file b.xml: sed... (3 Replies)
Discussion started by: RomitaaChawla@1
3 Replies

10. Shell Programming and Scripting

Need Help with a sed command involving Regex

Hi, Iam a newbie to SED. I'm faced with a problem as described. Given the file with text 1 rwerwerwe rere 2 fdfefefe fsdfds 3 rerere ffff trtrt 4 aaaa 1234 asadsdsd 5 hfjfjfjsjfsf... (14 Replies)
Discussion started by: SShinde
14 Replies
CPS::Functional(3pm)					User Contributed Perl Documentation				      CPS::Functional(3pm)

NAME
"CPS::Functional" - functional utilities in Continuation-Passing Style SYNOPSIS
use CPS::Functional qw( kmap ); use Example::HTTP::Client qw( k_get_http ); use List::Util qw( sum ); my @URLs = ( "http://www.foo.com", "http://www.bar.com", ); kmap( @URLs, sub { my ( $item, $kret ) = @_; k_get_http( uri => $item, on_response => sub { my ( $response ) = @_; $kret->( $response->content_length ); } ); }, sub { my ( @sizes ) = @_; say "Total length of all URLs: " . sum(@sizes); }, ); DESCRIPTION
This module provides CPS versions of data-flow functionals, such as Perl's "map" and "grep", where function bodies are invoked and expected to return data, which the functional manages. They are built on top of the control-flow functionals provided by the "CPS" module itself. FUNCTIONS
kmap( @items, &body, $k ) CPS version of perl's "map" statement. Calls the "body" code once for each element in @items, capturing the list of values the body passes into its continuation. When the items are exhausted, $k is invoked and passed a list of all the collected values. $body->( $item, $kret ) $kret->( @items_out ) $k->( @all_items_out ) kgrep( @items, &body, $k ) CPS version of perl's "grep" statement. Calls the "body" code once for each element in @items, capturing those elements where the body's continuation was invoked with a true value. When the items are exhausted, $k is invoked and passed a list of the subset of @items which were selected. $body->( $item, $kret ) $kret->( $select ) $k->( @chosen_items ) kfoldl( @items, &body, $k ) CPS version of "List::Util::reduce", which collapses (or "folds") a list of values down to a single scalar, by successively accumulating values together. If @items is empty, invokes $k immediately, passing in "undef". If @items contains a single value, invokes $k immediately, passing in just that single value. Otherwise, initialises an accumulator variable with the first value in @items, then for each additional item, invokes the "body" passing in the accumulator and the next item, storing back into the accumulator the value that "body" passed to its continuation. When the @items are exhausted, it invokes $k, passing in the final value of the accumulator. $body->( $acc, $item, $kret ) $kret->( $new_acc ) $k->( $final_acc ) Technically, this is not a true Scheme/Haskell-style "foldl", as it does not take an initial value. (It is what Haskell calls "foldl1".) However, if such an initial value is required, this can be provided by kfoldl( [ $initial, @items ], &body, $k ) kfoldr( @items, &body, $k ) A right-associative version of "kfoldl()". Where "kfoldl()" starts with the first two elements in @items and works forward, "kfoldr()" starts with the last two and works backward. $body->( $item, $acc, $kret ) $kret->( $new_acc ) $k->( $final_acc ) As before, an initial value can be provided by modifying the @items array, though note it has to be last this time: kfoldr( [ @items, $initial ], &body, $k ) kunfold( $seed, &body, $k ) An inverse operation to "kfoldl()"; turns a single scalar into a list of items. Repeatedly calls the "body" code, capturing the values it returns, until it indicates the end of the loop, then invoke $k with the collected values. $body->( $seed, $kmore, $kdone ) $kmore->( $new_seed, @items ) $kdone->( @items ) $k->( @all_items ) With each iteration, the "body" is invoked and passed the current $seed value and two continuations, $kmore and $kdone. If $kmore is invoked, the passed items, if any, are appended to the eventual result list. The "body" is then re-invoked with the new $seed value. If $klast is invoked, the passed items, if any, are appended to the return list, then the entire list is passed to $k. EXAMPLES
The following aren't necessarily examples of code which would be found in real programs, but instead, demonstrations of how to use the above functions as ways of controlling program flow. Without dragging in large amount of detail on an asynchronous or event-driven framework, it is difficult to give a useful example of behaviour that CPS allows that couldn't be done just as easily without. Nevertheless, I hope the following examples will be useful to demonstrate use of the above functions, in a way which hints at their use in a real program. Implementing "join()" using "kfoldl()" use CPS::Functional qw( kfoldl ); my @words = qw( My message here ); kfoldl( @words, sub { my ( $left, $right, $k ) = @_; $k->( "$left $right" ); }, sub { my ( $str ) = @_; print "Joined up words: $str "; } ); Implementing "split()" using "kunfold()" The following program illustrates the way that "kunfold()" can split a string, in a reverse way to the way "kfoldl()" can join it. use CPS::Functional qw( kunfold ); my $str = "My message here"; kunfold( $str, sub { my ( $s, $kmore, $kdone ) = @_; if( $s =~ s/^(.*?) // ) { return $kmore->( $s, $1 ); } else { return $kdone->( $s ); } }, sub { my @words = @_; print "Words in message: "; print "$_ " for @words; } ); Generating Prime Numbers While the design of "kunfold()" is symmetric to "kfoldl()", the seed value doesn't have to be successively broken apart into pieces. Another valid use for it may be storing intermediate values in computation, such as in this example, storing a list of known primes, to help generate the next one: use CPS::Functional qw( kunfold ); kunfold( [ 2, 3 ], sub { my ( $vals, $kmore, $kdone ) = @_; return $kdone->() if @$vals >= 50; PRIME: for( my $n = $vals->[-1] + 2; ; $n += 2 ) { $n % $_ == 0 and next PRIME for @$vals; push @$vals, $n; return $kmore->( $vals, $n ); } }, sub { my @primes = ( 2, 3, @_ ); print "Primes are @primes "; } ); Forward-reading Program Flow One side benefit of the CPS control-flow methods which is unassociated with asynchronous operation, is that the flow of data reads in a more natural left-to-right direction, instead of the right-to-left flow in functional style. Compare sub square { $_ * $_ } sub add { $a + $b } print reduce( &add, map( square, primes(10) ) ); (because "map" is a language builtin but "reduce" is a function with "(&)" prototype, it has a different way to pass in the named functions) with my $ksquare = liftk { $_[0] * $_[0] }; my $kadd = liftk { $_[0] + $_[1] }; kprimes 10, sub { kmap @_, $ksquare, sub { kfoldl @_, $kadd, sub { print $_[0]; } } }; This translates roughly to a functional vs imperative way to describe the problem: Print the sum of the squares of the first 10 primes. Take the first 10 primes. Square them. Sum them. Print. Admittedly the closure creation somewhat clouds the point in this small example, but in a larger example, the real problem-solving logic would be larger, and stand out more clearly against the background boilerplate. SEE ALSO
o CPS - manage flow of control in Continuation-Passing Style AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-06-27 CPS::Functional(3pm)
All times are GMT -4. The time now is 01:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy