Sponsored Content
Top Forums Shell Programming and Scripting Add substring in a file containing fixed length record. Post 302615951 by CarloM on Friday 30th of March 2012 09:49:22 AM
Old 03-30-2012
You're attempting to extract the substrings before you've read any records.
Code:
awk 'BEGIN {sum_a=0;sum_b=0; }
{
a=substr($0,389,3);b=substr($0,399,3)
printf"%d\t\t%d",a,b;
sum_a = sum_a+a;
sum_b = sum_b+b;
}
END {printf"%d\t\t%d",sum_a,sum_b}'

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

fixed record length

hello! I have a file with fixed record length... format: 123445asdfg 4343777 sfgg I wanna convert it to 123445,asdfg ,4343,777 ,sfgg is there any way to do it? sed/grep/awk?? at the moment I use sed -e 's_ \(\)_,\1_g' but it works only if there are spaces between... (16 Replies)
Discussion started by: george_
16 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

search and replace fixed length record file

Hi I need to be search a file of fixed length records and when I hit a particular record that match a search string, substitute a known position field In the example file below FHEAD000000000120090806143011 THEAD0000000002Y0000000012 P00000000000000001234 TTAIL0000000003... (0 Replies)
Discussion started by: nedkelly007
0 Replies

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

7. Shell Programming and Scripting

Add character based on record length

All, I can't seem to find exactly what I'm looking for, and haven't had any luck patching things together. I need to look through a file, and if the record length is not 874, then add 'E' in position 778. Your help is greatly appreciated. (4 Replies)
Discussion started by: CutNPaste
4 Replies

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

9. Shell Programming and Scripting

Fixed Length file from a SQL script

Hi, I have a DB2 UDB 9.7 SQL script, as follows: I need to pass the script into Unix and generate a fixed length file from this. Can someone kindly provide a script to achieve it? SELECT CAST(COALESCE(CL_ID,'000000000') AS CHAR(9)) AS CL_ID ,STATUS... (5 Replies)
Discussion started by: ebsus
5 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
MEMMEM(3)						     Linux Programmer's Manual							 MEMMEM(3)

NAME
memmem - locate a substring SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include <string.h> void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen); DESCRIPTION
The memmem() function finds the start of the first occurrence of the substring needle of length needlelen in the memory area haystack of length haystacklen. RETURN VALUE
The memmem() function returns a pointer to the beginning of the substring, or NULL if the substring is not found. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +----------+---------------+---------+ |Interface | Attribute | Value | +----------+---------------+---------+ |memmem() | Thread safety | MT-Safe | +----------+---------------+---------+ CONFORMING TO
This function is not specified in POSIX.1, but is present on a number of other systems. BUGS
In glibc 2.0, if needle is empty, memmem() returns a pointer to the last byte of haystack. This is fixed in glibc 2.1. SEE ALSO
bstring(3), strstr(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2017-03-13 MEMMEM(3)
All times are GMT -4. The time now is 06:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy