07-19-2005
Err well, typically you would identify a line by the presence of the '\n' character.
So, open the file. Go the end of the file. Work backwards towards the start of the file, counting the number of '\n'. When you have reached the required number of '\n' characters, store the position in the file.
Read from the stored position of the file to the end of file into memory buffer. Dump buffer contents into file.
Or something like that ...
Some useful functions are fopen, fclose, fread and fwrite.
Hope this helps.
MBB
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
Hello Firends,
I have file like below. I want to remove selected blocks say abc,pqr,lst. how can i remove those blocks from file.
zone abc {
blah
blah
blah }
zone xyz {
blah
blah
blah }
zone pqr {
blah
blah
blah } (4 Replies)
Discussion started by: nrbhole
4 Replies
2. Shell Programming and Scripting
Hi all.
I have a database log file in which log data get appended to it daily. I want to do a automatic maintainence of this log by going through the log and deleting lines belonging to a certain date.
How should i do it? Please help. Thanks.
Example. To delete all lines prior to Jun... (4 Replies)
Discussion started by: ahSher
4 Replies
3. Shell Programming and Scripting
Hi,
I have a file ( all_users.ldif ) of the following format:
cn=orcladmin, cn=Users, dc=maximus,dc=com
cn=PUBLIC, cn=Users, dc=maximus,dc=com
cn=portal,cn=users,dc=maximus,dc=com
cn=portal_admin,cn=users,dc=maximus,dc=com
cn=uddi_publisher,cn=Users,dc=maximus,dc=com... (4 Replies)
Discussion started by: itzz.me
4 Replies
4. Shell Programming and Scripting
I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it.
For example, Here is a portion of a zone file.
IN NS ns1.domain.tld.
IN NS ns2.domain.tld.
IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies
5. Shell Programming and Scripting
I need to delete those lines from a file, which starts with 45.
How to do it? (3 Replies)
Discussion started by: mady135
3 Replies
6. Shell Programming and Scripting
hi guys,
I have very large txt files (200GB) and just want to to delete the first two lines (headers). So far I used
sed -i '1,2d' infile.txtbut this command always takes extremely long as it writes all again. Is there a better way to do it (ie just to delete the lines without writing all... (2 Replies)
Discussion started by: TuAd
2 Replies
7. UNIX for Dummies Questions & Answers
Dear everyone,
I have a file with 900 lines (there is only numbers in one line, no string),
I only need the lines 2+3n (n=0,1...296), i.e line 2, 5, 8, 11...888.
I tried google but only the results such as how to delete all the odd lines or all the even lines with 'awk' command.
Thanks in... (4 Replies)
Discussion started by: phamnu
4 Replies
8. Shell Programming and Scripting
I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries.
The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies
9. Shell Programming and Scripting
I have some text files in a folder named ff as follows. I need to delete the lines (in-place editing)in these files based on another file aa.txt.
32bm.txt:
249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9
250... (2 Replies)
Discussion started by: aden
2 Replies
10. Shell Programming and Scripting
I'm trying to remove a specific number of lines, above and below a specific line of text, highlighted in red:
<STMTTRN>
<TRNTYPE>CREDIT
<DTPOSTED>20151205000001
<TRNAMT>10
<FITID>667800001
<CHECKNUM>667800001
<MEMO>BALANCE
</STMTTRN>
<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20151207000001... (8 Replies)
Discussion started by: bomsom
8 Replies
LEARN ABOUT NETBSD
fwrite
FREAD(3) BSD Library Functions Manual FREAD(3)
NAME
fread, fwrite -- binary stream input/output
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdio.h>
size_t
fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream);
size_t
fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream);
DESCRIPTION
The function fread() reads nmemb objects, each size bytes long, from the stream pointed to by stream, storing them at the location given by
ptr.
The function fwrite() writes nmemb objects, each size bytes long, to the stream pointed to by stream, obtaining them from the location given
by ptr.
Mixing fread() and fwrite() calls without setting the file position explicitly using fsetpos(3) between read and write or write and read
operations will lead to unexpected results because of buffering the file pointer not being set to the expected position after each operation
completes. This behavior is allowed by ANSI C for efficiency and it will not be changed.
RETURN VALUES
The functions fread() and fwrite() advance the file position indicator for the stream by the number of bytes read or written. They return
the number of objects read or written. If size or nmemb is 0, the functions return 0 and the state of stream remains unchanged. If an error
occurs, or the end-of-file is reached, the return value is a short object count (or zero).
The function fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which
occurred. The function fwrite() returns a value less than nmemb only if a write error has occurred.
SEE ALSO
read(2), write(2)
STANDARDS
The functions fread() and fwrite() conform to ANSI X3.159-1989 (``ANSI C89'').
BSD
September 11, 2011 BSD