Sponsored Content
Top Forums Shell Programming and Scripting Extracting fixed length number from a text file Post 302994213 by vgersh99 on Monday 20th of March 2017 12:33:24 PM
Old 03-20-2017
Quote:
Originally Posted by dsid
@vgersh. awk -F ' ' is for defining delimiters as far as I know, what does your command mean
Code:
awk -F'[][]'

. The next part is the start of the string I got that and I think $NF would be number of fields, but why are you subtracting 1 from it and then printing that out.
-F defines field delimiters. In this particular case the field delimiters are [] as the 23-digit long string is surrounded by [].
We subtract 1 from $NF because the LAST field is following the ]. The field next to last is your 23-digit long string.
This User Gave Thanks to vgersh99 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Shell Programming and Scripting

convert XML file into Text file(fixed length)

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> ... (0 Replies)
Discussion started by: ram2s2001
0 Replies

3. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

4. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

5. Shell Programming and Scripting

fixed length text file padding issues in AIX

Hi, I have a fixed length text file that needs to be cut into individual files in aix and facing padding issues. If I have multiple blank spaces in the file it is just making it one while cutting the files.. Eg:- $ - blank space filename:file.txt ... (2 Replies)
Discussion started by: techmoris
2 Replies

6. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

7. Shell Programming and Scripting

Help with extracting words from fixed length files

I am very new to scripting and need to write a script that will extract the account number from a line that begins with HDR. For example, the file is as follows HDR2010072600300405505100726 00300405505 LBJ FREEWAY DALLAS TELEGRAPH ... (9 Replies)
Discussion started by: bds052189
9 Replies

8. Shell Programming and Scripting

Insert a variable to a text file after fixed number of lines

Hi, I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines.. Please help me on this.. Thanks in Advance, Amrutha (3 Replies)
Discussion started by: amr89
3 Replies

9. UNIX for Dummies Questions & Answers

Fixed length file extracting values in columns

How do I extract values in a few columns in a row of a fixed length file? If there are 8 columns and I need to extract values of 2nd,4th and 6 th columns, how do i do that? I used cut command, this I used only for one column. How do I do it more than one column? The below command will give... (1 Reply)
Discussion started by: princetd001
1 Replies

10. UNIX for Dummies Questions & Answers

Length of a fixed width file

I have a fixed width file of length 53. when is try to get the lengh of the record of that file i get 2 different answers. awk '{print length;exit}' <File_name> The above code gives me length 50. wc -L <File_name> The above code gives me length 53. Please clarify on... (2 Replies)
Discussion started by: Amrutha24
2 Replies
CGI::FormBuilder::Template::Text(3pm)			User Contributed Perl Documentation		     CGI::FormBuilder::Template::Text(3pm)

NAME
CGI::FormBuilder::Template::Text - FormBuilder interface to Text::Template SYNOPSIS
my $form = CGI::FormBuilder->new( fields => @fields, template => { type => 'Text', template => 'form.tmpl', variable => 'form', } ); DESCRIPTION
This engine adapts FormBuilder to use "Text::Template". Usage is very similar to Template Toolkit: my $form = CGI::FormBuilder->new( fields => @fields, template => { type => 'Text', # use Text::Template template => 'form.tmpl', } ); The default options passed into "Text::Template->new()" with this calling form are: TYPE => 'FILE' SOURCE => 'form.tmpl' DELIMITERS => ['<%','%>'] As these params are passed for you, your template will look very similar to ones used by Template Toolkit and "HTML::Mason" (the Text::Template default delimiters are "{" and "}", but using alternative delimiters speeds it up by about 25%, and the "<%" and "%>" delimiters are good, familiar-looking alternatives). The following methods are provided (usually only used internally): engine Returns a reference to the "Text::Template" object prepare Returns a hash of all the fields ready to be rendered. render Uses the prepared hash and expands the template, returning a string of HTML. TEMPLATES
<% $jshead %> - JavaScript to stick in <head> <% $title %> - The <title> of the HTML form <% $start %> - Opening <form> tag and internal fields <% $submit %> - The submit button(s) <% $reset %> - The reset button <% $end %> - Closing </form> tag <% $fields %> - List of fields <% $field %> - Hash of fields (for lookup by name) Note that you refer to variables with a preceding "$", just like in Perl. Like Template Toolkit, you can specify a variable to place fields under: my $form = CGI::FormBuilder->new( fields => @fields, template => { type => 'Text', template => 'form.tmpl', variable => 'form' }, ); Unlike Template Toolkit, though, these will not be placed in OO-style, dot-separated vars. Instead, a hash will be created which you then reference: <% $form{jshead} %> <% $form{start} %> etc. And field data is in a hash-of-hashrefs format: For a field named... The field data is in... -------------------- ----------------------- job <% $form{field}{job} %] size <% $form{field}{size} %] email <% $form{field}{email} %] Since "Text::Template" looks so much like Perl, you can access individual elements and create variables like so: <% my $myfield = $form{field}{email}; $myfield->{label}; # text label $myfield->{field}; # field input tag $myfield->{value}; # first value $myfield->{values}; # list of all values $myfield->{options}; # list of all options $myfield->{required}; # required flag $myfield->{invalid}; # invalid flag $myfield->{error}; # error string if invalid %> <% for my $field (@{$form{fields}}) { $OUT .= "<tr> <td>" . $field->{label} . "</td> <td>" . $field->{field} . "</td> <tr>"; } %> In addition, when using the engine option, you supply an existing Text::Template object or a hash of parameters to be passed to "new()". For example, you can ask for different delimiters yourself: my $form = CGI::FormBuilder->new( fields => @fields, template => { type => 'Text', template => 'form.tmpl', variable => 'form', engine => { DELIMITERS => [ '[@--', '--@]' ], }, data => { version => 1.23, author => 'Fred Smith', }, }, ); If you pass a hash of parameters, you can override the "TYPE" and "SOURCE" parameters, as well as any other "Text::Template" options. For example, you can pass in a string template with "TYPE => STRING" instead of loading it from a file. You must specify both "TYPE" and "SOURCE" if doing so. The good news is this is trivial: my $form = CGI::FormBuilder->new( fields => @fields, template => { type => 'Text', variable => 'form', engine => { TYPE => 'STRING', SOURCE => $string, DELIMITERS => [ '[@--', '--@]' ], }, data => { version => 1.23, author => 'Fred Smith', }, }, ); If you get the crazy idea to let users of your application pick the template file (strongly discouraged) and you're getting errors, look at the "Text::Template" documentation for the "UNTAINT" feature. Also, note that "Text::Template"'s "PREPEND => 'use strict;'" option is not recommended due to the dynamic nature for "FormBuilder". If you use it, then you'll have to declare each variable that "FormBuilder" puts into your template with "use vars qw($jshead' ... etc);" If you're really stuck on this, though, a workaround is to say: PREPEND => 'use strict; use vars qw(%form);' and then set the option "variable => 'form'". That way you can have strict Perl without too much hassle, except that your code might be exhausting to look at :-). Things like $form{field}{your_field_name}{field} end up being all over the place, instead of the nicer short forms. Finally, when you use the "data" template option, the keys you specify will be available to the template as regular variables. In the above example, these would be "<% $version %>" and "<% $author %>". And complex datatypes are easy: data => { anArray => [ 1, 2, 3 ], aHash => { orange => 'tangy', chocolate => 'sweet' }, } This becomes the following in your template: <% @anArray; # you can use $myArray[1] etc. %aHash; # you can use $myHash{chocolate} etc. %> For more information, please consult the "Text::Template" documentation. SEE ALSO
CGI::FormBuilder, CGI::FormBuilder::Template, Text::Template REVISION
$Id: Text.pm 100 2007-03-02 18:13:13Z nwiger $ AUTHOR
Copyright (c) Nate Wiger <http://nateware.com>. All Rights Reserved. Text::Template support is due to huge contributions by Jonathan Buhacoff. Thanks man. This module is free software; you may copy this under the terms of the GNU General Public License, or the Artistic License, copies of which should have accompanied your Perl kit. perl v5.14.2 2011-09-16 CGI::FormBuilder::Template::Text(3pm)
All times are GMT -4. The time now is 08:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy