Sponsored Content
Top Forums Shell Programming and Scripting Awk command to replace specific position characters. Post 302594612 by Chubler_XL on Tuesday 31st of January 2012 07:11:37 PM
Old 01-31-2012
How about this:

Code:
awk 'function repl(s,f,t,v)
{ return substr(s,1,f-1) sprintf("%-*s", t-f+1, v) substr(s,t+1) }
{ a=repl($0,96,98,"ABC")
  a=repl(a,99,113,"DEF")
  a=repl(a,190,198,"XYZ")
  print a
}' infile

This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read space filled file and replace text at specific position

Hi I have a spaced filled file having records like below: What I want is to read line having RT3 at position 17-19 then go to position 2651 check the 18 characters (might be space filled till 18 characters). This position should have a... (6 Replies)
Discussion started by: COD
6 Replies

2. Shell Programming and Scripting

Using sed to replace specific character and specific position

I am trying to use sed to replace specific characters at a specific position in the file with a different value... can this be done? Example: File: A0199999123 A0199999124 A0199999125 Need to replace 99999 in positions 3-7 with 88888. Any help is appreciated. (5 Replies)
Discussion started by: programmer22
5 Replies

3. Shell Programming and Scripting

Add characters at specific position in file

Hello I want to add some value at the specific position. My file has data like Hello Welcome to UNIX Forums Need Assistance I want to add some value at the end but at same character position for all lines. I want my output file to have data like : Here '_' represents blanks.... (3 Replies)
Discussion started by: dashing201
3 Replies

4. Shell Programming and Scripting

Sed position specific replace

I'm drawing a blank on how to use sed to replace selectively based on position in the string (vs nth occurence): hello.|there.|how.|are.|you.| I want the period removed in the 3rd item (as defined by the pipe delimiter) if a period is present. So the result in this case would be: ... (2 Replies)
Discussion started by: tiggyboo
2 Replies

5. Shell Programming and Scripting

Using sed to replace a string in a specific position

I asked this before, but my problem got more complicated. Heres what I am trying to do: I'm trying to replace a string at a certain location with another string. Heres the file I'm trying to change: \E I want to replace the escape code at the 3rd line, 2nd column with this escape code... (3 Replies)
Discussion started by: tinman47
3 Replies

6. Shell Programming and Scripting

position specific replace in file

How to replace the position specific values in the file.. i searched a lot the forums but i couldn't able to do... i have file like below 576666666666666666666666666 7878 897987 121 0asdas Y12 5900fbb 777 09JJJ 78798347892374 234234234364 234232898 89HJHIHIGIUG989902743748327khjkhkjlh... (6 Replies)
Discussion started by: greenworld123
6 Replies

7. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

8. Shell Programming and Scripting

Find and replace with 0 for characters in a specific position

Need command for position based replace: I need a command to replace with 0 for characters in the positions 11 to 20 to all the lines starts with 6 in a file. For example the file ABC.txt has: abcdefghijklmnopqrstuvwxyz 6abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz... (4 Replies)
Discussion started by: thangabalu
4 Replies

9. Post Here to Contact Site Administrators and Moderators

Search for a pattern and replace a space at specific position with a Character in File

In file, we have millions of records each of 1000 in length. And at specific position say 800 there is a space, we need to replace it with Character X if the ID in that row starts with 123. So far i have used the below which is replacing space at that position to X but its not checking for... (3 Replies)
Discussion started by: Jagmeet Singh
3 Replies

10. Shell Programming and Scripting

sed command on AIX, replace specific characters

Hi, Im using sed on an AIX machine. I am trying to change the 137-139 characters if they are a ' 36'/'000' to a '036'. The positions that need to be changed are fixed. the source data that I have is$cat v.txt 4000422985400050462239065593606500000007422985707771046154054910075641MC0318AMWAY... (9 Replies)
Discussion started by: dsid
9 Replies
Devel::REPL::Overview(3pm)				User Contributed Perl Documentation				Devel::REPL::Overview(3pm)

NAME
Devel::REPL::Overview - overview of Devel::REPL. DESCRIPTION
What is a console? How it can assist you? Most modern languages have consoles. Console is an interactive tool that evaluates your input while you type it. It gives you several advantages: o Quickly test some thought or tricky expression o Run some code bigger than one line without a temporary file o Play around with libraries and modules o You can even call a console in your script and play around in script's context For Ruby it would be irb, for Python is... python byitself and for perl... and there was nothing for perl (except that ugly perl -d -e "" and several failed projects) until Devel::REPL was written by Matt S Trout (a.k.a. mst) from ShadowCatSystems <http://www.shadowcatsystems.co.uk>. Devel::REPL - the Perl console REPL stands for Read, Evaluate, Print, Loop. Lets install and try it. $ cpan Devel::REPL After installation you have a lot of new modules, but the most interesting things are: o Devel::REPL A top level module. o re.pl Wrapper script, running console. And a bunch of plugins (I'll describe them later). In command line type: $ re.pl If everything is ok you'll see a prompt (underlined $). That's it. You can start typing expressions. An example session: $ sub factorial { > my $number = shift; > return $number > 1 ? $number * factorial($number-1) : $number; > } $ factorial 1 # by the way, comments are allowed 1 # our return value $ factorial 5 120 $ [1,2,3,4,5,6,7] $ARRAY1 = [ 1, 2, 3, # return values are printed with Data::Dumper::Streamer. 4, # See Plugins section 5, 6, 7 ]; $ {apple=>1,fruit=>'apple',cart=>['apple','banana']} $HASH1 = { apple => 1, cart => [ 'apple', 'banana' ], fruit => 'apple' }; $ package MyPackage; # create a package $ sub say_hi { # define a sub > print "Hi! "; > } # statement is evaluated only after we've finished typing block. # See Plugins section. > __PACKAGE__ MyPackage > package main; > __PACKAGE_ main > MyPackage->say_hi Hi! 1 $ Control files a.k.a. I don't want to type it every time Devel::REPL has control files feature. Control files are evaluated on session start in the same way as you would type them manually in console. Default control file is located at `$HOME/.re.pl/repl.rc` . You can store there any statements you would normally type in. I.e. my `$HOME/.re.pl/repl.rc` has next lines: use feature 'say'; # to don't write all the time use Data::Dumper; # pretty print data structures sub pp { print Data::Dumper->Dump([@_]) } You can have multiple control files and they can be anywhere in the file system. To make re.pl use some rc-file other than repl.rc call it like this: $ re.pl --rcfile /path/to/your/rc.file If your rc-file is in `$HOME/.re.pl` directory, you can omit path: $ re.pl --rcfile rc.file If you have rc-file with the same name in current directory and you don't want to type path, you can: $ re.pl --rcfile ./rc.file I want it to bark, fly, jump and swim! or Plugins Plugins extend functionality and change behavor of Devel::REPL. Bundled plugins are: o Devel::REPL::Plugin::History No comments. Simply history. o Devel::REPL::Plugin::!LexEnv Provides a lexical environment for the Devel::REPL. o Devel::REPL::Plugin::DDS Formats return values with Data::Dump::Streamer module. o Devel::REPL::Plugin::Packages Keeps track of which package your're in. o Devel::REPL::Plugin::Commands Generic command creation plugin using injected functions. o Devel::REPL::Plugin::MultiLine::PPI Makes Devel::REPL read your input until your block is finished. What does this means: you can type a part of a block on one line and second part on another: $ sub mysub { > print "Hello, World! "; ## notice prompt change > } $ mysub Hello, World! 1 $ but this *doesn't* mean you can print sub name or identifier on several lines. Don't do that! It won't work. There are lots of contributed plugins you can find at CPAN. Profiles If plugins change and extend functionality of Devel::REPL, profiles are changing your environment (loaded plugins, constants, subs and etc.). There's only one bundled profile called `Devel::REPL::Profile::Default`, lets take a look at it: package Devel::REPL::Profile::Default; use Moose; ### advanced OOP system for Perl ### keep those exports/imports out of our namespace use namespace::clean -except => [ 'meta' ]; with 'Devel::REPL::Profile'; ## seem perldoc Muse sub plugins { ### plugins we want to be loaded qw(History LexEnv DDS Packages Commands MultiLine::PPI); } ### the only required sub for profile, ### it is called on profile activation sub apply_profile { my ($self, $repl) = @_; ### $self - no comments, $repl - current instance of Devel::REPL $repl->load_plugin($_) for $self->plugins; ### load our plugins } 1; At the moment there are no profiles on CPAN. Mostly you'll use control files. To enable some profile use --profile switch: $ re.pl --profile SomeProfile See Also Devel::REPL, Devel::REPL::Plugin, Devel::REPL::Profile perl v5.14.2 2010-05-08 Devel::REPL::Overview(3pm)
All times are GMT -4. The time now is 04:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy