Sponsored Content
Top Forums Shell Programming and Scripting Replace using awk on fixed width file. Post 302945271 by Chubler_XL on Wednesday 27th of May 2015 05:44:44 PM
Old 05-27-2015
It looks like your repl function was written to expect FROM and TO values so you should be calling it like this:

Code:
a=repl(a,478,487,"2011-01-01")


Or update repl() to use FROM and LENGTH as RudiC mentioned:

Code:
function repl(s,f,L,v)
{ return substr(s,1,f-1) sprintf("%-*s", L, v) substr(s,f+L) }


Code:
$ printf "%c" {1..9} {0..9} | awk '
function repl(s,f,L,v) { return substr(s,1,f-1) sprintf("%-*s", L, v) substr(s,f+L) }
{print repl($0,8,3,"AB") }'
1234567AB 123456789


Last edited by Chubler_XL; 05-27-2015 at 06:51 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Fixed Width file using AWK

I am using the following command at the Unix prompt to make my 'infile' into a fixed width file of 100 characters. awk '{printf "%-100s\n",$0}' infile > outfile However, there are some records with a special character "©" These records are using 3 characters in place of one and my record... (2 Replies)
Discussion started by: alok.benjwal
2 Replies

2. Shell Programming and Scripting

edit entire column from a fixed-width file using awk or sed

Col1 Col2 Col3 Col4 12 Completed 08 0830 12 In Progress 09 0829 11 For F U 07 0828 Considering the file above, how could i replace the third column the most efficient way? The actual file size is almost 1G. I am... (10 Replies)
Discussion started by: tamahomekarasu
10 Replies

3. Shell Programming and Scripting

Fixed Width Join & Pad Sed/Awk Help

I was wondering someone might be able to push me in the right direction, I am writing a script to modify fixed-width spool files, As you can see below the original spool file broke a single line into two for printability sake. I have had been able do the joins using sed, the thing I am... (10 Replies)
Discussion started by: Cho Nagurai
10 Replies

4. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

5. Shell Programming and Scripting

awk: creating a fixed-width single file from 2 different files

I have to create a single file from three files, Please see below for samples: day.txt 20090101 20090102 item.txt 123456789101 12345678910209 1234567891 str.txt 1 12 123 output.txt 20090101123456789101 1 0 2009010112345678910209 12 ... (2 Replies)
Discussion started by: tamahomekarasu
2 Replies

6. Shell Programming and Scripting

To replace the value of the column in a fixed width file

I have a fixed with file with header & trailer length having the same length of the detail record file. The details record length of this file is 24, for Header and Trailer the records will be padded with spaces to match the record length of the file Currently I am adding 3 spaces in header... (14 Replies)
Discussion started by: ginrkf
14 Replies

7. UNIX for Dummies Questions & Answers

Replace the unexpected newline char with space in a Fixed width file

Input eg: Ouput Expected. The #rd line had the unexpted new line, which need to be replaced with space. I was planing to go with checking the length of each line using awk and if the length is less than the defeined limit, (12 in above case) will replace the newline with space. ... (5 Replies)
Discussion started by: deepakwins
5 Replies

8. Shell Programming and Scripting

Print column details from fixed width file using awk command

hi, i have a fixed width file with multiple columns and need to print data using awk command. i use: awk -F "|" '($5 == BH) {print $1,$2,$3}' <non_AIM target>.txt for a delimiter file. but now i have a fixed width file like below: 7518 8269511BH 20141224951050N8262 11148 8269511BH... (5 Replies)
Discussion started by: kcdg859
5 Replies

9. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

10. Shell Programming and Scripting

Search and replace value based on certain conditions in a fixed width file

Hi Forum. I tried searching for a solution using the internet search but I haven't been able to find any solution for what I'm trying to accomplish. I have a fixed width column file where I need to search for any occurrences of "D0" in col pos.#1-2, 10-11, 20-21 and replaced it with "XD". ... (2 Replies)
Discussion started by: pchang
2 Replies
Devel::REPL(3pm)					User Contributed Perl Documentation					  Devel::REPL(3pm)

NAME
Devel::REPL - a modern perl interactive shell SYNOPSIS
my $repl = Devel::REPL->new; $repl->load_plugin($_) for qw(History LexEnv); $repl->run Alternatively, use the 're.pl' script installed with the distribution system$ re.pl DESCRIPTION
This is an interactive shell for Perl, commonly known as a REPL - Read, Evaluate, Print, Loop. The shell provides for rapid development or testing of code without the need to create a temporary source code file. Through a plugin system, many features are available on demand. You can also tailor the environment through the use of profiles and run control files, for example to pre-load certain Perl modules when working on a particular project. USAGE
To start a shell, follow one of the examples in the "SYNOPSIS" above. Once running, the shell accepts and will attempt to execute any code given. If the code executes successfully you'll be shown the result, otherwise an error message will be returned. Here are a few examples: $_ print "Hello, world! " Hello, world! 1 $_ nosuchfunction Compile error: Bareword "nosuchfunction" not allowed while "strict subs" in use at (eval 130) line 5. $_ In the first example above you see the output of the command ("Hello, world!"), if any, and then the return value of the statement(1). Following that example, an error is returned when the execution of some code fails. Note that the lack of semicolon on the end is not a mistake - the code is run inside a Block structure (to protect the REPL in case the code blows up), which means a single statement doesn't require the semicolon. You can add one if you like, though. If you followed the first example in the "SYNOPSIS" above, you'll have the History and LexEnv plugins loaded (and there are many more available). Although the shell might support "up-arrow" history, the History plugin adds "bang" history to that so you can re-execute chosen commands (with e.g. "!53"). The LexEnv plugin ensures that lexical variables declared with the "my" keyword will automatically persist between statements executed in the REPL shell. When you "use" any Perl module, the "import()" will work as expected - the exported functions from that module are available for immediate use: $_ carp "I'm dieeeing! " String found where operator expected at (eval 129) line 5, near "carp "I'm dieeeing! "" (Do you need to predeclare carp?) Compile error: syntax error at (eval 129) line 5, near "carp "I'm dieeeing! "" BEGIN not safe after errors--compilation aborted at (eval 129) line 5. $_ use Carp $_ carp "I'm dieeeing! " I'm dieeeing! at /usr/share/perl5/Lexical/Persistence.pm line 327 1 $_ To quit from the shell, hit "Ctrl+D" or "Ctrl+C". MSWin32 NOTE: control keys won't work if TERM=dumb because readline functionality will be disabled. Run Control Files For particular projects you might well end up running the same commands each time the REPL shell starts up - loading Perl modules, setting configuration, and so on. A run control file lets you have this done automatically, and you can have multiple files for different projects. By default the "re.pl" program looks for "$HOME/.re.pl/repl.rc", and runs whatever code is in there as if you had entered it at the REPL shell yourself. To set a new run control file that's also in that directory, pass it as a filename like so: system$ re.pl --rcfile myproject.pc If the filename happens to contain a forwardslash, then it's used absolutely, or realive to the current working directory: system$ re.pl --rcfile /path/to/my/project/repl.rc Within the run control file you might want to load plugins. This is covered in "The REPL shell object" section, below. Profiles To allow for the sharing of run control files, you can fashion them into a Perl module for distribution (perhaps via the CPAN). For more information on this feature, please see the Devel::REPL::Profile manual page. A default profile ships with "Devel::REPL"; it loads the following plugins: o Devel::REPL::Plugin::History o Devel::REPL::Plugin::LexEnv o Devel::REPL::Plugin::DDS o Devel::REPL::Plugin::Packages o Devel::REPL::Plugin::Commands o Devel::REPL::Plugin::MultiLine::PPI o Devel::REPL::Plugin::Colors o Devel::REPL::Plugin::Completion o Devel::REPL::Plugin::CompletionDriver::INC o Devel::REPL::Plugin::CompletionDriver::LexEnv o Devel::REPL::Plugin::CompletionDriver::Keywords o Devel::REPL::Plugin::CompletionDriver::Methods o Devel::REPL::Plugin::ReadlineHistory Plugins Plugins are a way to add funcionality to the REPL shell, and take advantage of "Devel::REPL" being based on the Moose object system for Perl 5. This means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins can change the way commands are interpreted, or the way their results are output, or even add commands to the shell environment. A number of plugins ship with "Devel::REPL", and more are available on the CPAN. Some of the shipped plugins are loaded in the default profile, mentioned above. These plugins can be loaded in your "$HOME/.re.pl/repl.rc" like: load_plugin qw( CompletionDriver::Global DumpHistory ); Writing your own plugins is not difficult, and is discussed in the Devel::REPL::Plugin manual page, along with links to the manual pages of all the plugins shipped with "Devel::REPL". The REPL shell object From time to time you'll want to interact with or manipulate the "Devel::REPL" shell object itself; that is, the instance of the shell you're currently running. The object is always available through the $_REPL variable. One common requirement is to load an additional plugin, after your profile and run control files have already been executed: $_ $_REPL->load_plugin('Timing'); 1 $_ print "Hello again, world! " Hello again, world! Took 0.00148296356201172 seconds. 1 $_ REQUIREMENTS
In addition to the contents of the standard Perl distribution, you will need the following: o Moose >= 0.74 o MooseX::Object::Pluggable >= 0.0009 o MooseX::Getopt >= 0.18 o MooseX::AttributeHelpers >= 0.16 o namespace::clean o File::HomeDir o Task::Weaken o B::Concise o Term::ANSIColor o Devel::Peek Optionally, some plugins if installed will require the following modules: o PPI o Data::Dump::Streamer o Data::Dumper::Concise o File::Next o Sys::SigAction o B::Keywords o Lexical::Persistence o App::Nopaste o Module::Refresh AUTHOR
Matt S Trout - mst (at) shadowcatsystems.co.uk (<http://www.shadowcatsystems.co.uk/>) CONTRIBUTORS
Stevan Little - stevan (at) iinteractive.com Alexis Sukrieh - sukria+perl (at) sukria.net epitaph mgrimes - mgrimes (at) cpan dot org Shawn M Moore - sartak (at) gmail.com Oliver Gorwits - oliver on irc.perl.org Andrew Moore - "<amoore@cpan.org>" Norbert Buchmuller "<norbi@nix.hu>" Dave Houston "<dhouston@cpan.org>" Chris Marshall LICENSE
This library is free software under the same terms as perl itself perl v5.14.2 2012-05-19 Devel::REPL(3pm)
All times are GMT -4. The time now is 09:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy