Sponsored Content
Top Forums Shell Programming and Scripting Split file by column value, each with header Post 302985790 by RavinderSingh13 on Tuesday 15th of November 2016 09:16:11 AM
Old 11-15-2016
Quote:
Originally Posted by RudiC
The output is redirected to the respective file, controlled by $5, as requested in post#1. If a new (i.e. not yet registered) $5 shows up in a line, the new file name is constructed in FN[$5], and then, all lines with the same $5 are assembled in the same file. The number of files (= different unique $5) is "unlimited" (except for system factors e.g. memory).
Hello Rudi,

Thank you for nice explanation, I would like to mention here wouldn't be it good to close the opened files or if there are too many files opened it may be an issue with it. Could you please put some light on this too, will be grateful to you sir.

Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split large file and add header and footer to each file

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (1 Reply)
Discussion started by: ashish4422
1 Replies

2. Shell Programming and Scripting

Split large file and add header and footer to each small files

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (7 Replies)
Discussion started by: ashish4422
7 Replies

3. UNIX for Dummies Questions & Answers

split header row into one column

So, I have a massive file with thousands of columns I want a list of the headers in one column in another file. So I need to strip off the top line (can use head-1) But how can I convert from this format: A B C D E F G to A B C D E F G (6 Replies)
Discussion started by: polly_falconer
6 Replies

4. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

5. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

6. UNIX for Dummies Questions & Answers

Column Header in the Spool file

Hi All, I have a problem with the column heading while spooling the data from the database. Since i want the column header, therefore i am not using SET HEADING OFF, and i am getting the header, but for the longer column name, some of the character from the column name is missing. for... (7 Replies)
Discussion started by: Pramod_009
7 Replies

7. Shell Programming and Scripting

Split and add header and trailer from input file

I need to split the file based on pattern from position 34-37 while retaining the header and trailer records in each individual split file Also is it possible to output the TOM and PAT records in the same output file ? I need the output file names same as xyz_pattern_Datetimestamp.txt ... (23 Replies)
Discussion started by: techedipro
23 Replies

8. Shell Programming and Scripting

Sort and Split file with header and custom name

Hi, I am using SUN SOLARIS (SunOS sun4v sparc SUNW, T5240). I have a huge data file with header and trailer. This file gets used into an ETL process. ETL skips the header record (which is the first record of the file) and loads the rest of the record. The file can be delimited (comma,... (5 Replies)
Discussion started by: Saanvi1
5 Replies

9. Shell Programming and Scripting

Split a file based on encountering header

I need to split a file based on headers found Input file file1 content: ADD john mickey DROP matt sam output of file F1 john mickey output of file F2 matt sam (5 Replies)
Discussion started by: Diddy
5 Replies

10. Shell Programming and Scripting

Split large xml into mutiple files and with header and footer in file

Split large xml into mutiple files and with header and footer in file tried below it splits unevenly and also i need help in adding header and footer command : csplit -s -k -f my_XML_split.xml extrfile.xml "/<Document>/" {1} sample xml <?xml version="1.0" encoding="UTF-8"?><Recipient>... (36 Replies)
Discussion started by: karthik
36 Replies
Dpkg::Compression::FileHandle(3)				   libdpkg-perl 				  Dpkg::Compression::FileHandle(3)

NAME
Dpkg::Compression::FileHandle - object dealing transparently with file compression SYNOPSIS
use Dpkg::Compression::FileHandle; $fh = Dpkg::Compression::FileHandle->new(filename=>"sample.gz"); print $fh "Something "; close $fh; $fh = Dpkg::Compression::FileHandle->new(); open($fh, ">", "sample.bz2"); print $fh "Something "; close $fh; $fh = Dpkg::Compression::FileHandle->new(); $fh->open("sample.xz", "w"); $fh->print("Something "); $fh->close(); $fh = Dpkg::Compression::FileHandle->new(filename=>"sample.gz"); my @lines = <$fh>; close $fh; $fh = Dpkg::Compression::FileHandle->new(); open($fh, "<", "sample.bz2"); my @lines = <$fh>; close $fh; $fh = Dpkg::Compression::FileHandle->new(); $fh->open("sample.xz", "r"); my @lines = $fh->getlines(); $fh->close(); DESCRIPTION
Dpkg::Compression::FileHandle is an object that can be used like any filehandle and that deals transparently with compressed files. By default, the compression scheme is guessed from the filename but you can override this behaviour with the method "set_compression". If you don't open the file explicitly, it will be auto-opened on the first read or write operation based on the filename set at creation time (or later with the "set_filename" method). Once a file has been opened, the filehandle must be closed before being able to open another file. STANDARD FUNCTIONS
The standard functions acting on filehandles should accept a Dpkg::Compression::FileHandle object transparently including "open" (only when using the variant with 3 parameters), "close", "binmode", "eof", "fileno", "getc", "print", "printf", "read", "sysread", "say", "write", "syswrite", "seek", "sysseek", "tell". Note however that "seek" and "sysseek" will only work on uncompressed files as compressed files are really pipes to the compressor programs and you can't seek on a pipe. FileHandle METHODS The object inherits from FileHandle so all methods that work on this object should work for Dpkg::Compression::FileHandle too. There may be exceptions though. PUBLIC METHODS
my $fh = Dpkg::Compression::FileHandle->new(%opts) Creates a new filehandle supporting on-the-fly compression/decompression. Supported options are "filename", "compression", "compression_level" (see respective set_* functions) and "add_comp_ext". If "add_comp_ext" evaluates to true, then the extension corresponding to the selected compression scheme is automatically added to the recorded filename. It's obviously incompatible with automatic detection of the compression method. $fh->ensure_open($mode) Ensure the file is opened in the requested mode ("r" for read and "w" for write). Opens the file with the recorded filename if needed. If the file is already open but not in the requested mode, then it errors out. $fh->set_compression($comp) Defines the compression method used. $comp should one of the methods supported by Dpkg::Compression or "none" or "auto". "none" indicates that the file is uncompressed and "auto" indicates that the method must be guessed based on the filename extension used. $fh->set_compression_level($level) Indicate the desired compression level. It should be a value accepted by the function "compression_is_valid_level" of Dpkg::Compression. $fh->set_filename($name, [$add_comp_ext]) Use $name as filename when the file must be opened/created. If $add_comp_ext is passed, it indicates whether the default extension of the compression method must be automatically added to the filename (or not). my $file = $fh->get_filename() Returns the filename that would be used when the filehandle must be opened (both in read and write mode). This function errors out if "add_comp_ext" is enableactivated while the compression method is set to "auto". The returned filename includes the extension of the compression method if "add_comp_ext" is enabled. $ret = $fh->use_compression() Returns "0" if no compression is used and the compression method used otherwise. If the compression is set to "auto", the value returned depends on the extension of the filename obtained with the get_filename method. my $real_fh = $fh->get_filehandle() Returns the real underlying filehandle. Useful if you want to pass it along in a derived object. DERIVED OBJECTS
If you want to create an object that inherits from Dpkg::Compression::FileHandle you must be aware that the object is a reference to a GLOB that is returned by Symbol::gensym() and as such it's not a HASH. You can store internal data in a hash but you have to use "*$self-"{...}> to access the associated hash like in the example below: sub set_option { my ($self, $value) = @_; *$self->{"option"} = $value; } AUTHOR
Raphael Hertzog <hertzog@debian.org> 1.16.0.3 2012-04-17 Dpkg::Compression::FileHandle(3)
All times are GMT -4. The time now is 10:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy