Sponsored Content
Top Forums Programming Extract part of an archive to a different file Post 302954752 by Don Cragun on Thursday 10th of September 2015 01:41:34 PM
Old 09-10-2015
The code has everything to do with it.

Why do you believe that you have to copy everything into an array before you write any of your desired output?

Open your input file. Seek to the offset of the first byte you want to copy. Read data from your input file and write it to your output file until you have copied all of the bytes you want to extract. You can do this one byte at a time (no buffering issues, but relatively slow for large transfers), one block at a time (trivial buffering, relatively faster), one block at a time tuned to input and output file disk block boundaries (more complex logic, possibly hardware/filesystem dependent, faster).
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to extract archive to a specified directory

Hi, I would like to extract the files from an archive which I have copied from a different server which has different file structures to my server. When I do a tar xvf archive_name, I get the error saying the file or directory cannot be found. How do I specify a desginated directory to... (4 Replies)
Discussion started by: john_trinh
4 Replies

2. UNIX for Dummies Questions & Answers

Extract a part of file name

Hi, I want to extract a part of filename and pass it as a parameter to one of the scripts. Could someone help. File name:- NLL_NAM_XXXXX.XXXXXXX_1_1.txt. Here i have to extract only XXXXX.XXXXXXX and the position will be constant. that means that i have to extract some n characters from... (6 Replies)
Discussion started by: dnat
6 Replies

3. UNIX for Dummies Questions & Answers

choose what to extract from tar archive

Hello! I want to extract a choosen directory (and its contents) from a tar archive and i have tried what i believe is every option i could find in the manual. I think i have done it once before, but i don't remeber how. Could anyone please tell me how to do? (2 Replies)
Discussion started by: noratx
2 Replies

4. Shell Programming and Scripting

How to extract certain part of log file?

Hi there, I'm having some problem with UNIX scripting (ksh), perhaps somebody can help me out? For example: ------------ Sample content of my log file (text file): -------------------------------------- File1: .... info_1 ... info_2 ... info_3 ... File2: .... info_1 ... info_2 ...... (10 Replies)
Discussion started by: superHonda123
10 Replies

5. Shell Programming and Scripting

extract part of text file

I need to extract the following lines from this text and put it in different files. From xxxx@gmail.com Thu Jun 10 21:15:46 2010 Return-Path: <xxxxx@gmail.com> X-Original-To: xxx@localhost Delivered-To:xxxx@localhost Received: from ubuntu (localhost ) by ubuntu (Postfix) with ESMTP... (11 Replies)
Discussion started by: waxo
11 Replies

6. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

7. Shell Programming and Scripting

Extract the part of sequences from a file

I have a text file, input.fasta contains some protein sequences. input.fasta is shown below. >P02649 MKVLWAALLVTFLAGCQAKVEQAVETEPEPELRQQTEWQSGQRWELALGRFWDYLRWVQT LSEQVQEELLSSQVTQELRALMDETMKELKAYKSELEEQLTPVAEETRARLSKELQAAQA RLGADMEDVCGRLVQYRGEVQAMLGQSTEELRVRLASHLRKLRKRLLRDADDLQKRLAVY... (8 Replies)
Discussion started by: rahim42
8 Replies

8. Shell Programming and Scripting

> dpkg-deb to Extract and Reconstruct a Multipart Archive???

Greetings! Here's one which has been bugging me for a bit ;) As might be known, LibreOffice is available to some of us Linux folk as a large set of debs. Of course, being a curious sort, I'd like to dig in and recreate the original tree which is composed of these assorted archives. So, I... (1 Reply)
Discussion started by: LinQ
1 Replies

9. UNIX for Dummies Questions & Answers

Extract tar archive on remote server in another directory

HI All Please suggest how to untar archive on remote sever. When im trying use regular command without any flags everything is working fine: $( ssh <user>@<server> -n '. ~/.profile >/dev/null 2>&1 ; cd /path_1 ; copiedIVR_name=`ls -tr | tail -1` ; tar xvf $copiedIVR_name ' ) but when im... (9 Replies)
Discussion started by: BACya
9 Replies

10. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies
setbuffer(3C)						   Standard C Library Functions 					     setbuffer(3C)

NAME
setbuffer, setlinebuf - assign buffering to a stream SYNOPSIS
#include <stdio.h> void setbuffer(FILE *iop, char *abuf, size_t asize); int setlinebuf(FILE *iop); DESCRIPTION
The setbuffer() and setlinebuf() functions assign buffering to a stream. The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as writ- ten; when it is block buffered, many characters are saved and written as a block; when it is line buffered, characters are saved until either a NEWLINE is encountered or input is read from stdin. The fflush(3C) function may be used to force the block out early. Normally all files are block buffered. A buffer is obtained from malloc(3C) upon the first getc(3C) or putc(3C) performed on the file. If the standard stream stdout refers to a terminal, it is line buffered. The standard stream stderr is unbuffered by default. The setbuffer() function can be used after a stream iop has been opened but before it is read or written. It uses the character array abuf whose size is determined by the asize argument instead of an automatically allocated buffer. If abuf is the null pointer, input/output will be completely unbuffered. A manifest constant BUFSIZ, defined in the <stdio.h> header, tells how large an array is needed: char buf[BUFSIZ]; The setlinebuf() function is used to change the buffering on a stream from block buffered or unbuffered to line buffered. Unlike set- buffer(), it can be used at any time that the stream iop is active. A stream can be changed from unbuffered or line buffered to block buffered by using freopen(3C). A stream can be changed from block buffered or line buffered to unbuffered by using freopen(3C) followed by setbuf(3C) with a buffer argument of NULL. RETURN VALUES
The setlinebuf() function returns no useful value. SEE ALSO
malloc(3C), fclose(3C), fopen(3C), fread(3C), getc(3C), printf(3C), putc(3C), puts(3C), setbuf(3C), setvbuf(3C) NOTES
A common source of error is allocating buffer space as an "automatic" variable in a code block, and then failing to close the stream in the same block. SunOS 5.10 13 May 1997 setbuffer(3C)
All times are GMT -4. The time now is 10:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy