Sponsored Content
Top Forums Programming How to delete N bytes from the starting of the file from a C function??? Post 302145922 by jockey007 on Thursday 15th of November 2007 08:53:18 PM
Old 11-15-2007
I even tried

lseek(fd, (off_t)numOfBytes, SEEK_SET);
i=ftruncate(fd,1000);

but this didn't help
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete bytes from file

I'm doing a bit of hex editing with dd and I can replace values fairly simply. However, I've run across a situation where I need to delete bytes in the file and I'm not sure how to do that. For example: Input file has: 1234567890 Output needs to be: 123abc90 I tried this: printf... (6 Replies)
Discussion started by: Loriel
6 Replies

2. Shell Programming and Scripting

Delete lines starting with XX or YY or ZZ or ....

Hi There! My final task for today is to delete lines starting with certain numbers for e.g., my text block is and i want to delete all lines starting with 11 or 17 or 21 I know i can use multiple sed commands like sed '/^11,/d' <filename> sed '/^17,/d' <filename> sed '/^21,/d'... (2 Replies)
Discussion started by: orno
2 Replies

3. Shell Programming and Scripting

How to delete initial N bytes from the starting of the file using sed?

I want to delete initial N bytes of a file using sed. How can I do that? (3 Replies)
Discussion started by: jockey007
3 Replies

4. Shell Programming and Scripting

Remove first N bytes and last N bytes from a binary file on AIX.

Hi all, Does anybody know or guide me on how to remove the first N bytes and the last N bytes from a binary file? Is there any AWK or SED or any command that I can use to achieve this? Your help is greatly appreciated!! Best Regards, Naveen. (1 Reply)
Discussion started by: naveendronavall
1 Replies

5. Shell Programming and Scripting

Delete a line in a file starting with - Perl one-liner

Hi I need a perl onliner to delete a line in a file starting with few words. Example file.txt ---------- my name is don I live in London I am woking as engineer I want to delete a line starting with 'I live in' using perl oneliner and in place edit with out temporary files Thanks... (2 Replies)
Discussion started by: ammu
2 Replies

6. Programming

Copying 1024 bytes data in 3-bytes chunk

Hi, If I want to copy a 1024 byte data stream in to the target location in 3-bytes chunk, I guess I can use the following script. dd bs=1024 count=3 if=/src of=/dest But, I would like to know, how to do it via a C program. I have tried this with memcpy(), that did not help. (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. UNIX for Dummies Questions & Answers

X bytes of 0, Y bytes of random data, Z bytes of 5, T bytes of 1. ??

Hello guys. I really hope someone will help me with this one.. So, I have to write this script who: - creates a file home/student/vmdisk of 10 mb - formats that file to ext3 - mounts that partition to /mnt/partition - creates a file /mnt/partition/data. In this file, there will... (1 Reply)
Discussion started by: razolo13
1 Replies

8. UNIX for Advanced & Expert Users

How to delete a* file with out deleting file name starting with a?

Hi, I have a query: I have a bunch of files starting letter with 'a' (example: abhi,all,anand,animal,a1.txt,allow.java,a*) here i want to delete/remove only a* folder but not other files and folders. and a* folder is present in so many other folders. what is unix command to delete... (9 Replies)
Discussion started by: rajanikanth86
9 Replies

9. Shell Programming and Scripting

Shell script - entered input(1-40 bytes) needs to be converted exactly 40 bytes

hello, suppose, entered input is of 1-40 bytes, i need it to be converted to 40 bytes exactly. example: if i have entered my name anywhere between 1-40 i want it to be stored with 40 bytes exactly. enter your name: donald duck (this is of 11 bytes) expected is as below - display 11... (3 Replies)
Discussion started by: shravan.300
3 Replies

10. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies
truncate(2)							System Calls Manual						       truncate(2)

NAME
truncate, ftruncate - Changes file length SYNOPSIS
#include <unistd.h> int truncate( const char *path, off_t length); int ftruncate( int filedes, off_t length); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: ftruncate(), truncate(): XSH4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the name of a file that is opened, truncated, and then closed. The path parameter must point to a pathname which names a regular file for which the calling process has write permission. If the path parameter refers to a symbolic link, the length of the file pointed to by the symbolic link is truncated. Specifies the descriptor of a file that must be open for writing. Specifies the new length of the file in bytes. DESCRIPTION
The truncate() and ftruncate() functions change the length of a file to the size in bytes specified by the length parameter. If the new length is less than the previous length, the truncate() and ftruncate() functions remove all data beyond length bytes from the specified file. All file data between the new end-of-file and the previous end-of-file is discarded. If the new length is greater than the previous length, one byte of zero (0x00) is written at the offset of the new length. The space in between the previous end-of-file and the new end- of-file is left as a hole; that is, no blocks are allocated to the space in between the previous last block and the new last block. Full blocks are returned to the file system so that they can be used again, and the file size is changed to the value of the length parame- ter. The truncate() and ftruncate() functions have no effect on FIFO special files or directories. These functions do not modify the seek pointer of the file. Upon successful completion, the truncate() and ftruncate() functions mark the st_ctime and st_mtime fields of the file for update. If the file is a regular file, the ftruncate() and truncate() functions clear the S_ISUID and S_ISGID attributes of the file. If the file has enforced file locking enabled and there are file locks on the file, the truncate() or ftruncate() function fails. RETURN VALUES
Upon successful completion, a value of 0 (zero) is returned. If the truncate() or ftruncate() function fails, it returns a value of -1, and errno is set to indicate the error. ERRORS
The ftruncate() and truncate() functions set errno to the specified values for the following conditions: [Tru64 UNIX] The write operation failed due to an enforced write lock on the file. [Tru64 UNIX] The file has enforced mode file locking enabled and there are file locks on the file. The length parameter was greater than the maximum file size. A signal was caught during execution. The length parameter was less than 0 (zero). [Tru64 UNIX] The file is not a regular file. An I/O error occurred while reading from or writing to a file system. [Tru64 UNIX] The process' root or current directory is located in a virtual file system that has been unmounted. In addition, the ftruncate() function sets errno to the specified values for the following conditions: [Tru64 UNIX] Write access permis- sion to the file was denied. The filedes parameter is not a valid file descriptor open for writing. The fildes parameter references a file that was opened without write permission. [Tru64 UNIX] The file resides on a read-only file system. In addition, the truncate() function fails if errors occur that apply to any service requiring pathname resolution, or if one of the fol- lowing are true: A component of the path prefix denies search permission, or write permission is denied on the file. The named file is a directory. Too many symbolic links were encountered in resolving path. The size of the pathname exceeds PATH_MAX or a pathname component is longer than NAME_MAX. A component of the specified pathname does not exist, or the path parameter points to an empty string. A compo- nent of the path prefix is not a directory. The file resides on a read-only file system. RELATED INFORMATION
Functions: chmod(2), fcntl(2), open(2) Standards: standards(5) delim off truncate(2)
All times are GMT -4. The time now is 09:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy