Sponsored Content
Top Forums Shell Programming and Scripting how to get the specified content of the text into a variable. Post 302410889 by vino on Wednesday 7th of April 2010 05:27:00 AM
Old 04-07-2010
Quote:
Originally Posted by dineshmurs
Thanks for your replay.After using the above cmd i am getting the following error
Error
====
No such file or directory
Test1.sh[21]: ./usr1/Server/temp/app.env ./usr1/Server/temp/upp/app.env ./usr1/Server/ORIG_temp/app.env ./usr1/Server/ORIG_temp/upp/app.env ./usr1/Server/work_temp_40/app.env ./usr1/Server/work_temp_40/upp/app.env ./usr1/fd/app.env ./usr1/PurgeArchive/app.env ./usr1/bm/bin/app.env ./usr1/apps/bin/app.env ./usr1/apps/ORIG_bin/app.env: cannot open


For your reference i am pasting the code

Code
======
find_name=$(find . -name "app.env");
var=$(tr ' ' "\n" < $find_name| grep "\/temp\/app.env")
Please post the entire script.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace a variable content

Hi, variable1="This is a car" Now I want to replace the content of variable1, "car" to "dog". Is there any simple command I can use. Thanks. Joseph (4 Replies)
Discussion started by: josephwong
4 Replies

2. Shell Programming and Scripting

Content of Content of a variable!

I got a sample BASH script like this : $ cat test MYVAR=$1 DUMMY1="This is tricky" DUMMY2=24 echo $ $ ./test DUMMY1 ./test: line 5: This is tricky: syntax error in expression (error token is "is tricky") **I was expecting the output as "This is tricky", ah! but no luck **But... (2 Replies)
Discussion started by: jaduks
2 Replies

3. Shell Programming and Scripting

Content of variable

I have a variable that contains filenames like this: variable="file_1.extension<blank>file_2.extension<blank>file_3.extension<blank>file_4.extension and so on" How can I make filenames to be separated by newline: (I tried Sed but it didn't worked well) file_1.extension file_2.extension... (6 Replies)
Discussion started by: MartyIX
6 Replies

4. Shell Programming and Scripting

addressing variable content...

I want to address a variable content whose name is/matches the content of a given other variable. i.e. set name=´sam´ set ${name}_age=´27´ So, by typing: echo ${name}_age I correctly obtain: sam_age By typing: echo $sam_age or echo ${sam_age} I correctly obtain: 27 But how can I... (3 Replies)
Discussion started by: sobolev
3 Replies

5. Shell Programming and Scripting

How to get content of a variable into text file (sed)?

Hello, Im working on this problem for 3 days now and i just cant get it to work.. I tried with alot of different sed methods but didnt find any solution. Its proberly verry simple but i just started bash scripting for a month or so.. i have a file called: file.nfo and file.txt the content... (4 Replies)
Discussion started by: atmosroll
4 Replies

6. Shell Programming and Scripting

How to put content of file into a variable?

For example, I have a simple text file note: this a note a simple note a very very simple notewhen I use this command, temp=$(cat "note.txt")then I echo temp, the result is in one line. echo $temp note: this a note a simple note a very very simple noteMy variable doesn't have newline. How... (7 Replies)
Discussion started by: 14th
7 Replies

7. Shell Programming and Scripting

Loop over variable content

Hello all, I do have a variable containing one line like this: Waiting for job XXXXXX to start I needed to get the 'XXXXXX' literal, so I did the following: job_interno=`echo $log_exec | sed 's/.*Waiting for job \(*\).*/\1/' ` #other stuff Now, my variable is have more... (5 Replies)
Discussion started by: manolain
5 Replies

8. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

Hello everyone, I work under Ubuntu 11.10 (c-shell) I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment. I will show you an example: - On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Discussion started by: tenteyu
1 Replies

9. UNIX for Dummies Questions & Answers

Getting ls content into a file using variable

hi i just cant figure out how can i do this ls -lt > log.txt using $PWD what i mean is how can i get the ls command content into a file using $PWD variable? :confused: (4 Replies)
Discussion started by: chinababy
4 Replies

10. Shell Programming and Scripting

Replacement of variable by their content in a file

Dear all, I have a "SQL request" in a file: that request include different "host variable" and I would like to substitute the different "host variable" by their respective content before executing the request. For example: $ echo $SHELL /bin/bash $ cat dae2.txt DELETE FROM ... (11 Replies)
Discussion started by: dae
11 Replies
Plack::Middleware(3pm)					User Contributed Perl Documentation				    Plack::Middleware(3pm)

NAME
Plack::Middleware - Base class for easy-to-use PSGI middleware SYNOPSIS
package Plack::Middleware::Foo; use parent qw( Plack::Middleware ); sub call { my($self, $env) = @_; # Do something with $env # $self->app is the original app my $res = $self->app->($env); # Do something with $res return $res; } # then in app.psgi use Plack::Builder; my $app = sub { ... } # as usual builder { enable "Plack::Middleware::Foo"; enable "Plack::Middleware::Bar", %options; $app; }; DESCRIPTION
Plack::Middleware is a utility base class to write PSGI middleware. All you have to do is to inherit from Plack::Middleware and then implement the callback "call" method (or "to_app" method that would return the PSGI code reference) to do the actual work. You can use "$self->app" to call the original (wrapped) application. Your middleware object is created at a PSGI application compile time and is persistent during the web server life cycle (unless it is a non-persistent environment such as CGI), so you should never set or cache per-request data like $env in your middleware object. See also "OBJECT LIFECYCLE" in Plack::Component. See Plack::Builder how to actually enable middleware in your .psgi application file using the DSL. If you do not like our builder DSL, you can also use "wrap" method to wrap your application with a middleware: use Plack::Middleware::Foo; my $app = sub { ... }; $app = Plack::Middleware::Foo->wrap($app, %options); $app = Plack::Middleware::Bar->wrap($app, %options); RESPONSE CALLBACK
The typical middleware is written like this: package Plack::Middleware::Something; use parent qw(Plack::Middleware); sub call { my($self, $env) = @_; # pre-processing $env my $res = $self->app->($env); # post-processing $res return $res; } The tricky thing about post processing the response is that it could either be an immediate 3 element array ref, or a code reference that implements the delayed (streaming) interface. Dealing with these two types of response in each piece of middleware is pointless, so you're recommended to use the "response_cb" wrapper function in Plack::Util when implementing a post processing middleware. my $res = $app->($env); Plack::Util::response_cb($res, sub { my $res = shift; # do something with $res; }); The callback function gets a PSGI response as a 3 element array reference, and you can update the reference to implement the post processing. package Plack::Middleware::Always500; use parent qw(Plack::Middleware); use Plack::Util; sub call { my($self, $env) = @_; my $res = $self->app->($env); Plack::Util::response_cb($res, sub { my $res = shift; $res->[0] = 500; return; }); } In this example, the callback gets the $res and updates its first element (status code) to 500. Using "response_cb" makes sure that this works with the delayed response too. You're not required (and not recommended either) to return a new array reference - they will be simply ignored. You're suggested to explicitly return, unless you fiddle with the content filter callback (see below). Similarly, note that you have to keep the $res reference when you swap the entire response. Plack::Util::response_cb($res, sub { my $res = shift; $res = [ $new_status, $new_headers, $new_body ]; # THIS DOES NOT WORK return; }); This does not work, since assigning a new anonymous array to $res doesn't update the original PSGI response value. You should instead do: Plack::Util::response_cb($res, sub { my $res = shift; @$res = ($new_status, $new_headers, $new_body); # THIS WORKS return; }); The third element of PSGI response array ref is a body, and it could be either array ref or IO::Handle-ish object. The application could also make use of $writer object if "psgi.streaming" is in effect. Dealing with these variants is again really painful, and "response_cb" can take care of that too, by allowing you to return a content filter as a code reference. # replace all "Foo" in content body with "Bar" Plack::Util::response_cb($res, sub { my $res = shift; return sub { my $chunk = shift; return unless defined $chunk; $chunk =~ s/Foo/Bar/g; return $chunk; } }); The callback takes one argument $chunk and your callback is expected to return the updated chunk. If the given $chunk is undef, it means the stream has reached the end, so your callback should also return undef, or return the final chunk and return undef when called next time. SEE ALSO
Plack Plack::Builder Plack::Component perl v5.14.2 2011-06-22 Plack::Middleware(3pm)
All times are GMT -4. The time now is 12:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy