Sponsored Content
Top Forums Programming Can we use write() to modify/update intermediate records in a file Post 302132002 by porter on Tuesday 14th of August 2007 05:12:50 PM
Old 08-14-2007
int fd=open(filename,O_RDWR);
lseek(fd,position,SEEK_SET);
write(fd,data,datalen);
close(fd);
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies

2. Shell Programming and Scripting

Help needed in removing intermediate segments from a pipe delimited segment file

Hi, I just stuckup in doing some regular expressions on a file. I have data which has multiple FHS and BTS segments like: FHS|12121|LOCAL|2323 MSH|10101|POTAMAS|2323 PID|121221|THOMAS|DAVID|23432 OBX|2342|H1211|3232 BTS|0000|MERSTO|LIABLE FHS|12121|LOCAL|2323 MSH|10101|POTAMAS|2323... (3 Replies)
Discussion started by: naren_0101bits
3 Replies

3. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

4. UNIX for Dummies Questions & Answers

update records in a file using shell script...

Hi, I have a file with 6 columns. First 3 columns together make unique record. I have a variable ($v) which hold a value that is obtained by a caliculaion. I have to replace value in 5th columnn with the value of the variable ($v). The value $v is caliculated from col4 and col6 values. ... (2 Replies)
Discussion started by: new_learner
2 Replies

5. Shell Programming and Scripting

insert a header in a huge data file without using an intermediate file

I have a file with data extracted, and need to insert a header with a constant string, say: H|PayerDataExtract if i use sed, i have to redirect the output to a seperate file like sed ' sed commands' ExtractDataFile.dat > ExtractDataFileWithHeader.dat the same is true for awk and... (10 Replies)
Discussion started by: deepaktanna
10 Replies

6. Shell Programming and Scripting

Push records to array during implicit loop and write to file

NEWBIE ALERT! Hi, I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies

7. Linux

Suggest update of two commands - who to write to?

I think it's about time the df and du commands (executables?) were updated to display gigabyte units without one having to do their own calculations from the -m option (display in megabytes). This is one of those "little nothing" annoyances that, at the same time, would positively show new... (3 Replies)
Discussion started by: SilversleevesX
3 Replies

8. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

9. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

10. Shell Programming and Scripting

Remove duplicated records and update last line record counts

Hi Gurus, I need to remove duplicate line in file and update TRAILER (last line) record count. the file is comma delimited, field 2 is key to identify duplicated record. I can use below command to remove duplicated. but don't know how to replace last line 2nd field to new count. awk -F","... (11 Replies)
Discussion started by: green_k
11 Replies
FCNTL(2)							System Calls Manual							  FCNTL(2)

NAME
fcntl - miscellaneous file descriptor control functions SYNOPSIS
#include <fcntl.h> int fcntl(int fd, int *cmd, [data]) DESCRIPTION
Fcntl() performs several file descriptor related functions, like duplicating a file descriptor, setting the "close on exec" attribute, etc. The fd argument is the file descriptor to operate on, cmd is the command code of the operation to perform, and data is an optional argument to give or receive parameters. The command codes and other symbols and types are declared in <fcntl.h>. The commands are: fcntl(fd, F_DUPFD, int fd2) Returns a new file descriptor that is a duplicate of file descriptor fd. It shares the same file pointer and the same file status flags, but has separate file descriptor flags that are initially off. The value of the duplicate file descriptor is the first free file descriptor greater than or equal to fd2. fcntl(fd, F_GETFD) Returns the file descriptor flags associated with file descriptor fd. The flags are the "close on exec" flag FD_CLOEXEC that, when set, causes the file descriptor to be closed when the process executes another program. The Minix-vmd specific FD_ASYNCHIO flag marks a file descriptor for asynchronous I/O operation. fcntl(fd, F_SETFD, int flags) Set the file descriptor flags of fd to flags. fcntl(fd, F_GETFL) Return the file status flags and file access modes associated with the file associated with file descriptor fd. The file status flags are O_NONBLOCK (non blocking I/O) and O_APPEND (append mode). The file access modes are O_RDONLY (read-only), O_WRONLY (write-only) and O_RDWR (read-write). These flags are also used in the second argument of open(2). fcntl(fd, F_SETFL, int flags) Set the file status flags of the file referenced by fd to flags. Only O_NONBLOCK and O_APPEND may be changed. Access mode flags are ignored. The next four commands use a parameter of type struct flock that is defined in <fcntl.h> as: struct flock { short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ short l_whence; /* SEEK_SET, SEEK_CUR, or SEEK_END */ off_t l_start; /* byte offset to start of segment */ off_t l_len; /* length of segment */ pid_t l_pid; /* process id of the locks' owner */ }; This structure describes a segment of a file. L_type is the lock operation performed on the file segment: F_RDLCK to set a read lock, F_WRLCK to set a write lock, and F_UNLCK to remove a lock. Several processes may have a read lock on a segment, but only one process can have a write lock. L_whence tells if the l_start offset must be interpreted from the start of the file (SEEK_SET), the current file posi- tion (SEEK_CUR), or the end of the file (SEEK_END). This is analogous to the third parameter of lseek(2). These SEEK_* symbols are declared in <unistd.h>. L_start is the starting offset of the segment of the file. L_end is the length of the segment. If zero then the segment extends until end of file. L_pid is the process-id of the process currently holding a lock on the segment. It is returned by F_GETLK. fcntl(fd, F_GETLK, struct flock *lkp) Find out if some other process has a lock on a segment of the file associated by file descriptor fd that overlaps with the segment described by the flock structure pointed to by lkp. If the segment is not locked then l_type is set to F_UNLCK. Otherwise an flock structure is returned through lkp that describes the lock held by the other process. L_start is set relative to the start of the file. fcntl(fd, F_SETLK, struct flock *lkp) Register a lock on a segment of the file associated with file descriptor fd. The file segment is described by the struct flock pointed to by lkp. This call returns an error if any part of the segment is already locked. fcntl(fd, F_SETLKW, struct flock *lkp) Register a lock on a segment of the file associated with file descriptor fd. The file segment is described by the struct flock pointed to by lkp. This call blocks waiting for the lock to be released if any part of the segment is already locked. fcntl(fd, F_FREESP, struct flock *lkp) Free a segment of disk space occupied by the file associated with file descriptor fd. The segment is described by the struct flock pointed to by lkp. The file is truncated in length to the byte position indicated by l_start if l_len is zero. If l_len is nonzero then the file keeps its size, but the freed bytes now read as zeros. (Other than sharing the flock structure, this call has nothing to do with locking.) fcntl(fd, F_SEEK, u64_t pos) This Minix-vmd specific call sets the file position of the file associated with file descriptor fd to the byte offset indicated by the 64-bit number pos. This is analogous to the call lseek(fd, pos, SEEK_SET) except that F_SEEK can be used on devices larger than 4 gigabyte. SEE ALSO
open(2), dup(2), lseek(2), ftruncate(3), int64(3). DIAGNOSTICS
Fcntl returns a file descriptor, flags, or 0 to indicate success. On error -1 is returned, with errno set to the appropriate error code. The most notable errors are: EINTR If a blocked F_SETLKW operation is interrupted by a signal that is caught. EAGAIN By F_SETLK if a segment cannot be locked. EBADF A bad file descriptor in general, or an attempt to place a write lock on a file that is not open for writing, etc. ENOLCK No locks available, the file system code has run out of internal table space. AUTHOR
Kees J. Bot (kjb@cs.vu.nl) FCNTL(2)
All times are GMT -4. The time now is 04:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy