Sponsored Content
Top Forums Shell Programming and Scripting [Solved] How to increment and add variable length numbers to a variable in a loop? Post 302771038 by Yoda on Tuesday 19th of February 2013 11:26:30 AM
Old 02-19-2013
Code:
awk ' /^[0-9]/{s+=substr($0,85,9)}END{printf "%09d\n", s } ' filename

With code tags, the data looks different! No need for condition, just action:
Code:
awk '{s+=substr($0,85,9)}END{printf "%09d\n", s } ' file

This User Gave Thanks to Yoda 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

the given code goes in infinite loop and does not increment variable i

code is as #!/bin/sh i=1; while do welcome $i times; i='expr $i+1'; done exit 0; (6 Replies)
Discussion started by: mrityunjay22
6 Replies

3. Shell Programming and Scripting

how to add Loop number to variable name?

Hi there, I need to add a sequence of numbers to existing variables within the script to be able to call the variable automatically. Somehow it's just printing the loop number. Here's what I've got so far. :eek: #!/bin/sh FOLDER1=foo FOLDER2=bar FOLDER3=beer for ((a=1; a <= 3 ; a++))... (2 Replies)
Discussion started by: siul0_0
2 Replies

4. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

5. Shell Programming and Scripting

Increment of a variable

Hi All, I have a variable n that stores a number. Eg. echo $n comes out to be 120. I need to print 121 using echo command on n. Please advice. Thanks in advance !! (4 Replies)
Discussion started by: learning_skills
4 Replies

6. Shell Programming and Scripting

Split variable length and variable format CSV file

Dear all, I have basic knowledge of Unix script and her I am trying to process variable length and variable format CSV file. The file length will depend on the numbers of Earnings/Deductions/Direct Deposits. And The format will depend on whether it is Earnings/Deductions or Direct Deposits... (2 Replies)
Discussion started by: chechun
2 Replies

7. 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

8. Shell Programming and Scripting

[Solved] Assigning a value to a variable name then running a loop on these values

Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer. I have input files containing something like File 1 Apples Apples Apples Apples File 2 Bananas Bananas Bananas Bananas (4 Replies)
Discussion started by: hubleo
4 Replies

9. Shell Programming and Scripting

[SOLVED] UNIX FOR loop to read a variable with multiple values

Hi, I have a variable which stores file names as a result of find command. I need to delete all these files one by one, i.e. by a loop. Can anyone tell me how can it be done? The variable f2d has the file names like these abc.txt bcd.txt fff.txt gef.txt Now I have used a loop as... (12 Replies)
Discussion started by: jhilmil
12 Replies

10. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies
srec_intel16(5) 						File Formats Manual						   srec_intel16(5)

NAME
srec_intel16 - Intel Hexadecimal 16-bit file format specification DESCRIPTION
This format is also known as the INHX16 format. This document describes the hexadecimal object file format for 16-bit microprocessors. This format is very similar to the srec_intel(5) format, except that the addresses are word addresses. The count field is a word count. The hexadecimal representation of binary is coded in ASCII alphanumeric characters. For example, the 8-bit binary value 0011-1111 is 3F in hexadecimal. To code this in ASCII, one 8-bit byte containing the ASCII code for the character '3' (0011-0011 or 0x33) and one 8-bit byte containing the) ASCII code for the character 'F' (0100-0110 or 0x46) are required. For each byte value, the high-order hexadecimal digit is always the first digit of the pair of hexadecimal digits. This representation (ASCII hexadecimal) requires twice as many bytes as the binary representation. A hexadecimal object file is blocked into records, each of which contains the record type, length, memory load address and checksum in addition to the data. There are currently six (6) different types of records that are defined, not all combinations of these records are meaningful, however. The record are: o Data Record o End of File Record o Extended Segment Address Record o Start Segment Address Record o Extended Linear Address Record o Start Linear Address Record General Record Format +-------+--------+--------+--------+--------+--------+ |Record | Record | Load | Record | Data | Check | |Mark | Length | Offset | Type | | sum | +-------+--------+--------+--------+--------+--------+ Record Mark. Each record begins with a Record Mark field containing 0x3A, the ASCII code for the colon (":") character. Record Length Each record has a Record Length field which specifies the number of 16-bit words of information or data which follows the Record Type field of the record. This field is one byte, represented as two hexadecimal characters. The maximum value of the Record Length field is hexadecimal 'FF' or 255. Load Offset Each record has a Load Offset field which specifies the 16-bit starting load offset of the data words, therefore this field is only used for Data Records (if the words are loaded as bytes, the address needs to be doubled). In other records where this field is not used, it should be coded as four ASCII zero characters ("0000" or 0x30303030). This field one 16-bit word, represented as four hexadecimal characters. Record Type Each record has a Record Type field which specifies the record type of this record. The Record Type field is used to interpret the remaining information within the record. This field is one byte, represented as two hexadecimal characters. The encoding for all the current record types are: 0 Data Record 1 End of File Record 5 Execution Start Address Record Data Each record has a variable length Data field, it consists of zero or more 16-bit words encoded as set of 4 hexadecimal digits, most significant digit first. The interpretation of this field depends on the Record Type field. Checksum Each record ends with a Checksum field that contains the ASCII hexadecimal representation of the two's complement of the 8-bit bytes that result from converting each pair of ASCII hexadecimal digits to one byte of binary, from and including the Record Length field to and including the last byte of the Data field. Therefore, the sum of all the ASCII pairs in a record after converting to binary, from the Record Length field to and including the Checksum field, is zero. Data Record (8-, 16- or 32-bit formats) +-------+--------+--------+--------+--------+--------+ |Record | Record | Load | Record | Data | Check | |Mark | Length | Offset | Type | | sum | |(":") | | | | | | +-------+--------+--------+--------+--------+--------+ The Data Record provides a set of hexadecimal digits that represent the ASCII code for data bytes that make up a portion of a memory image. The contents of the individual fields within the record are: Record Mark This field contains 0x3A, the hexadecimal encoding of the ASCII colon (":") character. Record Length The field contains two ASCII hexadecimal digits that specify the number of 16-bit data words in the record. The maximum value is 255 decimal. Load Offset This field contains four ASCII hexadecimal digits representing the word address at which the first word of the data is to be placed. (For an exquivalent bytes address, double it.) Record Type This field contains 0x3030, the hexadecimal encoding of the ASCII character "00", which specifies the record type to be a Data Record. Data This field contains sets of four ASCII hexadecimal digits, one set for each 16-bit data word, most significant digit first. Checksum This field contains the check sum on the Record Length, Load Offset, Record Type, and Data fields. Execution Start Address Record +-------+--------+--------+--------+--------+--------+ |Record | Record | Load | Record | EIP (4 | Check | |Mark | Length | Offset | Type | bytes) | sum | |(":") | (4) | (0) | (5) | | | +-------+--------+--------+--------+--------+--------+ The Execution Start Address Record is used to specify the execution start address for the object file. This is where the loader is to jump to begin execution once the hex load is complete. The Execution Start Address Record can appear anywhere in a hexadecimal object file. If such a record is not present in a hexadecimal object file, a loader is free to assign a default execution start address. The contents of the individual fields within the record are: Record mark This field contains 0x3A, the hexadecimal encoding of the ASCII colon (":") character. Record length The field contains 0x3032, the hexadecimal encoding of the ASCII characters "02", which is the length, in bytes, of the EIP regis- ter content within this record. Load Offset This field contains 0x30303030, the hexadecimal encoding of the ASCII characters "0000", since this field is not used for this record. Record Type This field contains 0x3035, the hexadecimal encoding of the ASCII character "05", which specifies the record type to be a Start Address Record. EIP This field contains eight ASCII hexadecimal digits that specify the address. The field is encoded big-endian (most significant digit first). Checksum This field contains the check sum on the Record length, Load Offset, Record Type, and EIP fields. End of File Record This shall be the last record in the file. +-------+--------+--------+--------+--------+ |Record | Record | Load | Record | Check | |Mark | Length | Offset | Type | sum | |(":") | (0) | (0) | (1) | (0xFF) | +-------+--------+--------+--------+--------+ The End of File Record specifies the end of the hexadecimal object file. The contents of the individual fields within the record are: Record mark This field contains 0x3A, the hexadecimal encoding of the ASCII colon (":") character. Record Length The field contains 0x3030, the hexadecimal encoding of the ASCII characters "00". Since this record does not contain any Data bytes, the length is zero. Load Offset This field contains 0x30303030, the hexadecimal encoding of the ASCII characters "0000", since this field is not used for this record. Record Type This field contains 0x3031, the hexadecimal encoding of the ASCII character "01", which specifies the record type to be an End of File Record. Checksum This field contains the check sum an the Record Length, Load Offset, and Record Type fields. Since all the fields are static, the check sum can also be calculated statically, and the value is 0x4646, the hexadecimal encoding of the ASCII characters "FF". Size Multiplier In general, binary data will expand in sized by approximately 2.3 times when represented with this format. EXAMPLE
Here is an example INHX16 file. It contains the data "Hello, World" to be loaded at address 0. :0700000065486C6C2C6F5720726F646CFF0AA8 :00000001FF COPYRIGHT
srec_cat version 1.58 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Peter Miller The srec_cat program comes with ABSOLUTELY NO WARRANTY; for details use the 'srec_cat -VERSion License' command. This is free software and you are welcome to redistribute it under certain conditions; for details use the 'srec_cat -VERSion License' command. AUTHOR
Peter Miller E-Mail: pmiller@opensource.org.au //* WWW: http://miller.emu.id.au/pmiller/ Reference Manual SRecord srec_intel16(5)
All times are GMT -4. The time now is 04:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy