Sponsored Content
Top Forums Shell Programming and Scripting Append line based on fixed position Post 302176737 by ashikin_8119 on Wednesday 19th of March 2008 04:09:18 AM
Old 03-19-2008
Thanks Ramesh

It works perfectly!!...really appreciate your help
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spliting the line based on position.

i want to split a big line based on the position. example : I have a single line which has 2300 characters. i want to split from 1 character to 300th characters as first line and 301th to 600 as second line and 601th to 900 as third line ...till the end of the string. Can anyone help... (1 Reply)
Discussion started by: senthil_is
1 Replies

2. UNIX for Dummies Questions & Answers

Append line and variable at fixed postion in file in unix

Hi I have a input file ::: 1583904589034853904 1690234849023849023 159823890238409 1690238490238490238490 . . . The output file should have the record 16 appended to the record 15 and a variable should be added at a FIXED POSTION at 55. The records are been processed inside a loop... (3 Replies)
Discussion started by: akashhello
3 Replies

3. Shell Programming and Scripting

append each line on fixed position 31 to 33

I have a .DAT file like below. 26666666660001343 000001004OLF 029100020090820 27777777770000060 000001004ODL-CH001000020090820 28888888880000780 000001013OLF 006500020090820 ....... ........ and so on..... I want to append each line in a file in .KSH script with XXX with position... (5 Replies)
Discussion started by: kshuser
5 Replies

4. Shell Programming and Scripting

Match data based on two fields, and append to a line

I need to write a program to do something like a 'vlookup' in excel. I want to match data from file2 based on two fields (where both match) in file1, and for matching lines, add the data from two of the fields from file2 to file1. If anyone knows something in perl or awk that can do this, I'd be... (20 Replies)
Discussion started by: jamessmith01
20 Replies

5. Shell Programming and Scripting

Remove the spaces at the end of a line starting from a fixed position

I want to remove the trailing spaces at the end of each line starting from a particular position(using ksh script). For example, in the attached file, I want to remove all the spaces starting from the position 430 till the end. The space has to be removed only from the 430th position no matter in... (3 Replies)
Discussion started by: Suryaaravindh
3 Replies

6. Shell Programming and Scripting

Print the complete line based on position as input

Hi , I have a text file like below abcd2223232321212121324343 asdsfffhfgfgfhgfhghghghghghgh dfdfdfgfghfgfgfgfgfgghghghghgh dfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdf 1234567890sasasasfdfbffghffhf abcd222323232121212abcdsds in the above file i need to grep and print the lines if 14th to 18th... (4 Replies)
Discussion started by: aravindj80
4 Replies

7. Shell Programming and Scripting

Fixed width file search based on position value

Hi, I am unable to find the right option to extract the data in the fixed width file. sample data abcd1234xgyhsyshijfkfk hujk9876 io xgla loki8787eljuwoejroiweo dkfj9098 dja Search based on position 8-9="xg" and print the entire row output ... (4 Replies)
Discussion started by: onesuri
4 Replies

8. Shell Programming and Scripting

Splitting based on occurence of a Character at fixed position

I have a requirement where i need to split a file based on occurence of a character which is present at a fixed position. Description is as below: 1. The file will be more than 1 Lakh records. 2. Each line will be of fixed length of 987 characters. 3. At position 28 in each line either 'C' or... (9 Replies)
Discussion started by: Neelkanth
9 Replies

9. Shell Programming and Scripting

To append new data at the end of each line based on substring of last column

Hi guys, I need to append new data at the end of each line of the files. This new data is based on substring (3rd fields) of last column. Input file xxx.csv: U1234|1-5X|orange|1-5X|Act|1-5X|0.1 /sac/orange 12345 0 U5678|1-7X|grape|1-7X|Act|1-7X|0.1 /sac/grape 5678 0... (5 Replies)
Discussion started by: null7
5 Replies

10. UNIX for Beginners Questions & Answers

Append each line based upon the character size

I have a huge file which contains multiple lines. It need to check whether character length is not more than 255 each line. If its not then it should remove the character up to column. I have described in the output below. If its more than that the next line should start with call but if the... (1 Reply)
Discussion started by: JoshvaPeter
1 Replies
FMEMOPEN(3)						     Linux Programmer's Manual						       FMEMOPEN(3)

NAME
fmemopen - open memory as stream SYNOPSIS
#include <stdio.h> FILE *fmemopen(void *buf, size_t size, const char *mode); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): fmemopen(): Since glibc 2.10: _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _GNU_SOURCE DESCRIPTION
The fmemopen() function opens a stream that permits the access specified by mode. The stream allows I/O to be performed on the string or memory buffer pointed to by buf. The mode argument specifies the semantics of I/O on the stream, and is one of the following: r The stream is opened for reading. w The stream is opened for writing. a Append; open the stream for writing, with the initial buffer position set to the first null byte. r+ Open the stream for reading and writing. w+ Open the stream for reading and writing. The buffer contents are truncated (i.e., '' is placed in the first byte of the buffer). a+ Append; open the stream for reading and writing, with the initial buffer position set to the first null byte. The stream maintains the notion of a current position, the location where the next I/O operation will be performed. The current position is implicitly updated by I/O operations. It can be explicitly updated using fseek(3), and determined using ftell(3). In all modes other than append, the initial position is set to the start of the buffer. In append mode, if no null byte is found within the buffer, then the initial position is size+1. If buf is specified as NULL, then fmemopen() allocates a buffer of size bytes. This is useful for an application that wants to write data to a temporary buffer and then read it back again. The initial position is set to the start of the buffer. The buffer is automatically freed when the stream is closed. Note that the caller has no way to obtain a pointer to the temporary buffer allocated by this call (but see open_memstream(3)). If buf is not NULL, then it should point to a buffer of at least len bytes allocated by the caller. When a stream that has been opened for writing is flushed (fflush(3)) or closed (fclose(3)), a null byte is written at the end of the buf- fer if there is space. The caller should ensure that an extra byte is available in the buffer (and that size counts that byte) to allow for this. In a stream opened for reading, null bytes ('') in the buffer do not cause read operations to return an end-of-file indication. A read from the buffer will indicate end-of-file only when the current buffer position advances size bytes past the start of the buffer. Write operations take place either at the current position (for modes other than append), or at the current size of the stream (for append modes). Attempts to write more than size bytes to the buffer result in an error. By default, such errors will be visible (by the absence of data) only when the stdio buffer is flushed. Disabling buffering with the following call may be useful to detect errors at the time of an output operation: setbuf(stream, NULL); RETURN VALUE
Upon successful completion, fmemopen() returns a FILE pointer. Otherwise, NULL is returned and errno is set to indicate the error. VERSIONS
fmemopen() was already available in glibc 1.0.x. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +------------+---------------+---------+ |Interface | Attribute | Value | +------------+---------------+---------+ |fmemopen(), | Thread safety | MT-Safe | +------------+---------------+---------+ CONFORMING TO
POSIX.1-2008. This function is not specified in POSIX.1-2001, and is not widely available on other systems. POSIX.1-2008 specifies that 'b' in mode shall be ignored. However, Technical Corrigendum 1 adjusts the standard to allow implementation- specific treatment for this case, thus permitting the glibc treatment of 'b'. NOTES
There is no file descriptor associated with the file stream returned by this function (i.e., fileno(3) will return an error if called on the returned stream). With version 2.22, binary mode (see below) was removed, many longstanding bugs in the implementation of fmemopen() were fixed, and a new versioned symbol was created for this interface. Binary mode From version 2.9 to 2.21, the glibc implementation of fmemopen() supported a "binary" mode, enabled by specifying the letter 'b' as the second character in mode. In this mode, writes don't implicitly add a terminating null byte, and fseek(3) SEEK_END is relative to the end of the buffer (i.e., the value specified by the size argument), rather than the current string length. An API bug afflicted the implementation of binary mode: to specify binary mode, the 'b' must be the second character in mode. Thus, for example, "wb+" has the desired effect, but "w+b" does not. This is inconsistent with the treatment of mode by fopen(3). Binary mode was removed in glibc 2.22; a 'b' specified in mode has no effect. BUGS
In versions of glibc before 2.22, if size is specified as zero, fmemopen() fails with the error EINVAL. It would be more consistent if this case successfully created a stream that then returned end-of-file on the first attempt at reading; since version 2.22, the glibc implementation provides that behavior. In versions of glibc before 2.22, specifying append mode ("a" or "a+") for fmemopen() sets the initial buffer position to the first null byte, but (if the current position is reset to a location other than the end of the stream) does not force subsequent writes to append at the end of the stream. This bug is fixed in glibc 2.22. In versions of glibc before 2.22, if the mode argument to fmemopen() specifies append ("a" or "a+"), and the size argument does not cover a null byte in buf, then, according to POSIX.1-2008, the initial buffer position should be set to the next byte after the end of the buffer. However, in this case the glibc fmemopen() sets the buffer position to -1. This bug is fixed in glibc 2.22. In versions of glibc before 2.22, when a call to fseek(3) with a whence value of SEEK_END was performed on a stream created by fmemopen(), the offset was subtracted from the end-of-stream position, instead of being added. This bug is fixed in glibc 2.22. The glibc 2.9 addition of "binary" mode for fmemopen() silently changed the ABI: previously, fmemopen() ignored 'b' in mode. EXAMPLE
The program below uses fmemopen() to open an input buffer, and open_memstream(3) to open a dynamically sized output buffer. The program scans its input string (taken from the program's first command-line argument) reading integers, and writes the squares of these integers to the output buffer. An example of the output produced by this program is the following: $ ./a.out '1 23 43' size=11; ptr=1 529 1849 Program source #define _GNU_SOURCE #include <string.h> #include <stdio.h> #include <stdlib.h> #define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) int main(int argc, char *argv[]) { FILE *out, *in; int v, s; size_t size; char *ptr; if (argc != 2) { fprintf(stderr, "Usage: %s '<num>...' ", argv[0]); exit(EXIT_FAILURE); } in = fmemopen(argv[1], strlen(argv[1]), "r"); if (in == NULL) handle_error("fmemopen"); out = open_memstream(&ptr, &size); if (out == NULL) handle_error("open_memstream"); for (;;) { s = fscanf(in, "%d", &v); if (s <= 0) break; s = fprintf(out, "%d ", v * v); if (s == -1) handle_error("fprintf"); } fclose(in); fclose(out); printf("size=%zu; ptr=%s ", size, ptr); free(ptr); exit(EXIT_SUCCESS); } SEE ALSO
fopen(3), fopencookie(3), open_memstream(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-09-15 FMEMOPEN(3)
All times are GMT -4. The time now is 03:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy