Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to insert a string and variable at specified position in command in bash? Post 303042145 by RudiC on Monday 16th of December 2019 12:40:40 PM
Old 12-16-2019
Oh? Changing basic data again?


Be aware that a good, decent, stable, consistent specification helps everyone dealing with your request, saving time and efforts.


And, either of the three solutions given above can easily be adapted to your old and new and ever changing data (structures). This is left as an exercise to the interested reader.
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

2. Shell Programming and Scripting

search a line and insert string into specific at position

Hi, guys. I have one question: How can I search for a line with certain string in it and then insert a string into this line? For example: There is a file called shadow, the contents of it are below: ************************** ... yuanz:VIRADxMsadfDF/Q:0:0:50:7:::... (9 Replies)
Discussion started by: daikeyang
9 Replies

3. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

4. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Need command or script to print all lines from 2nd position to last but one position

hi guys, i want command or script to display the content of file from 2nd position to last but one position of a file abcdefghdasdasdsd 123,345,678,345,323 434,656,656,656,656 678,878,878,989,545 4565656667,65656 i want to display the same above file without first and... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

9. UNIX for Beginners Questions & Answers

Bash: Insert in a variable a file

hi all i have a problem in the bash shell. i'd like insert in a variable a file for example : i have a file datafine.log in this file there is : 17/JUN/2019 i want to insert the value of datafine.log in a variable. Regards Frncesco edit by bakunin: please use CODE-tags for your data... (2 Replies)
Discussion started by: Francesco_IT
2 Replies

10. UNIX for Beginners Questions & Answers

How to insert subnode in xml file using xmlstarlet or any other bash command?

I have multiple xml files where i want to update a subnode if the subnode project points to different project or insert a subnode if it doesn't exist using a xmlstarlet or any other command that can be used in a bash script. I have been able to update the subnode project if it doesn't point to... (1 Reply)
Discussion started by: Sekhar419
1 Replies
Catalyst::Model::Adaptor(3pm)				User Contributed Perl Documentation			     Catalyst::Model::Adaptor(3pm)

NAME
Catalyst::Model::Adaptor - use a plain class as a Catalyst model SYNOPSIS
Given a good old perl class like: package NotMyApp::SomeClass; use Moose; # to provide "new" sub method { 'yay' } Wrap it with a Catalyst model: package MyApp::Model::SomeClass; use base 'Catalyst::Model::Adaptor'; __PACKAGE__->config( class => 'NotMyApp::SomeClass' ); Then you can use "NotMyApp::SomeClass" from your Catalyst app: sub action :Whatever { my ($self, $c) = @_; my $someclass = $c->model('SomeClass'); $someclass->method; # yay } Note that "NotMyApp::SomeClass" is instantiated at application startup time. If you want the adapted class to be created for call to "$c->model", see Catalyst::Model::Factory instead. If you want the adapted class to be created once per request, see Catalyst::Model::Factory::PerRequest. DESCRIPTION
The idea is that you don't want your Catalyst model to be anything other than a line or two of glue. Using this module ensures that your Model classes are separate from your application and therefore are well-abstracted, reusable, and easily testable. Right now there are too many modules on CPAN that are Catalyst-specific. Most of the models would be better written as a class that handles most of the functionality with just a bit of glue to make it work nicely with Catalyst. This module aims to make integrating your class with Catalyst trivial, so you won't have to do any extra work to make your model generic. For a good example of a Model that takes the right design approach, take a look at Catalyst::Model::DBIC::Schema. All it does is glues an existing DBIx::Class::Schema to Catalyst. It provides a bit of sugar, but no actual functionality. Everything important happens in the "DBIx::Class::Schema" object. The end result of that is that you can use your app's DBIC schema without ever thinking about Catalyst. This is a Good Thing. Catalyst is glue, not a way of life! CONFIGURATION
Subclasses of this model accept the following configuration keys, which can be hard-coded like: package MyApp::Model::SomeClass; use base 'Catalyst::Model::Adaptor'; __PACKAGE__->config( class => 'NotMyApp::SomeClass' ); Or be specified as application config: package MyApp; MyApp->config->{'Model::SomeClass'} = { class => 'NotMyApp::SomeClass' }; Or in your ConfigLoader-loaded config file: --- Model::SomeClass: class: NotMyApp::SomeClass args: foo: ... bar: ... This is exactly like every other Catalyst component, so you should already know this. Anyway, here are the options: class This is the name of the class you're adapting to Catalyst. It MUST be specified. Your application will die horribly if it can't require this package. constructor This is the name of the class method in "class" that will create an instance of the class. It defaults to "new". Your application will die horribly if it can't call this method. args This is a hashref of arguments to pass to the constructor of "class". It is optional, of course. If you omit it, nothing is passed to the constructor (as opposed to "{}", an empty hashref). METHODS
There are no methods that you call directly. When you call "$c->model" on a model that subclasses this, you'll get back an instance of the class being adapted, not this model. These methods are called by Catalyst: COMPONENT Setup this component. CUSTOMIZING THE PROCESS
By default, the instance of your adapted class is instantiated like this: my $args = $self->prepare_arguments($app); # $app sometimes called $c $adapted_class->$constructor($self->mangle_arguments($args)); Since a static hashref of arguments may not be what $class needs, you can override the following methods to change what $args is. prepare_arguments This method is passed the entire configuration for the class and the Catalyst application, and returns the hashref of arguments to be passed to the constructor. If you need to get dynamic data out of your application to pass to the consturctor, do it here. By default, this method returns the "args" configuration key. Example: sub prepare_arguments { my ($self, $app) = @_; # $app sometimes written as $c return { foobar => $app->config->{foobar}, baz => $self->{baz} }; } mangle_arguments This method is passed the hashref from "prepare_arguments", mangles them into a form that your constructor will like, and returns the mangled form. If your constuctor wants a list instead of a hashref, this is your opportunity to do the conversion. Example: sub mangle_arguments { my ($self, $args) = @_; return %$args; # now the args are a plain list } If you need to do more than this, you might as well just write the whole class yourself. This module is designed to make the common case work with 1 line of code. For special needs, it's easier to just write the model yourself. SEE ALSO
If you need a new instance returned each time "$c->model" is called, use Catalyst::Model::Factory instead. If you need to have exactly one instance created per request, use Catalyst::Model::Factory::PerRequest instead. AUTHOR
Jonathan Rockway "<jrockway@cpan.org>" LICENSE
This module is Copyright (c) 2007 Jonathan Rockway. You may use, modify, and redistribute it under the same terms as Perl itself. perl v5.10.1 2010-08-04 Catalyst::Model::Adaptor(3pm)
All times are GMT -4. The time now is 10:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy