Sponsored Content
Top Forums Shell Programming and Scripting split a file but output file is fixed Post 302273436 by jaduks on Sunday 4th of January 2009 09:25:25 PM
Old 01-04-2009
RahulJoshi,

Not sure if this is the requirement you are asking.

Code:
$ split -d -l 6 bigfile subfile

will create subfile00 subfile01 .... with each file of 6 lines

As you want 3 files in output, the l value has to be caluculated like this:

$ awk 'END {printf("%d\n",NR/3+.5)}' bigfile

------------
** The above way of rounding may go wrong in some cases, e.g. suppose the file is having 17 lines, 

$ awk 'END {printf("%d\n",NR/5+.5)}' bigfile
3

then,

$ split -d -l 3 bigfile subfile

will create 4 subfiles, which is wrong. 
------------

I am sure there can be better solutions to this. Group please.


Last edited by jaduks; 01-04-2009 at 10:26 PM.. Reason: typo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert XML file into Text file(fixed length)

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> ... (0 Replies)
Discussion started by: ram2s2001
0 Replies

2. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

3. UNIX for Dummies Questions & Answers

cleaning up spaces from fixed width file while converting to csv file

Open to a sed/awk/or perl alternative so that i can stick command into my bash script. This is a problem I resolve using a combination of cut commands - but that is getting convoluted. So would really appreciate it if someone could provide a better solution which basically replaces all... (3 Replies)
Discussion started by: svn
3 Replies

4. Shell Programming and Scripting

How to split a fixed width text file into several ones based on a column value?

Hi, I have a fixed width text file without any header row. One of the columns contains a date in YYYYMMDD format. If the original file contains 3 dates, I want my shell script to split the file into 3 small files with data for each date. I am a newbie and need help doing this. (14 Replies)
Discussion started by: bhanja_trinanja
14 Replies

5. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

6. Shell Programming and Scripting

adding file extensions to split output files

Hello, I've searched this forum and others for a solution to my problem but nothing seems just right, I'm hoping I can get some help (seems like this should be easy, and I apologize if I've missed something on the forum): I have several large .fastq DNA sequence files (~20million reads,... (2 Replies)
Discussion started by: ljk
2 Replies

7. Shell Programming and Scripting

Split: File into multiple and keeping the same 3 lines from input into all output files

The following code will split the infile into multiple files. However, I need it to insert the same first 3 lines from the original input file into each splitted file. How do I modify my script below to do so: print -n "Enter file name to split? " ; read infile if then echo "Invalid file... (4 Replies)
Discussion started by: mrn6430
4 Replies

8. UNIX for Advanced & Expert Users

Help on Shell Scripting - to store output to a fixed file

Hi I have a file called "test.txt" and it looks like this x y z x/c y/c/b now, i want to run a command and its output will be like this x 10 y/c/b 20 z 78 -------- my requirement is, i want to add the command output to "test.txt" as like below x 10 y ... (1 Reply)
Discussion started by: siva kumar
1 Replies

9. Shell Programming and Scripting

Regex to split a string and write the output in another file.

hi, i am trying to write a script to generate ouput in the following format: ##### buildappi abcd_sh nodebug.##### ##### buildappi ijk_sh nodebug.##### The given string is as follows: xtopSharedDLLs = "abcd_sh def_sh ijk_sh " \ + "jkl_sh any_sh... (15 Replies)
Discussion started by: Rashid Khan
15 Replies

10. Shell Programming and Scripting

Split a fixed length file bases on last occurence of string

Hi, I need to split a file based on last occurece of a string. PFB the explanation I have a file in following format aaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccccc ddddddddddddddddddddddddddd 3186rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr... (4 Replies)
Discussion started by: Neelkanth
4 Replies
uuls(1M)																  uuls(1M)

NAME
uuls - list spooled uucp transactions grouped by transaction SYNOPSIS
[directories]... [directories]... [directories]... DESCRIPTION
The commands, including are targeted for removal from HP-UX; see the below. This command lists the contents of UUCP spool directories (default with the files in each directory grouped into three categories: o Transactions, o Orphans, and o Others. Transactions Each output line starts with a transaction control filename, and includes the name of each local (same-directory) subfile referenced by the control file (see below). Each is possibly followed by the total size in bytes option) or Kbytes option) in the transaction (see below). The (meanings) option replaces the subfile names with nodename, user, and commandline information (see below). Orphans All subfiles not referenced by any control file. Others All other files in the directory (all files not listed under one of the above categories). Filenames are formatted into columns, so there can be more than one file per line. If a transaction has more subfiles than fit on one line, it is followed by continuation lines which are indented further. The (size in bytes) and (Kbytes) options cause the command to follow each transaction in the section with a total size for all stat-able, sendable files in that transaction. This includes files only, not or files. It does include stat-able files outside the spool directory that are indirectly referenced by files. Sizes are either in bytes or rounded to the nearest Kbyte (1024 bytes), respectively. A totals line is also added at the end of the section. The (meanings) option causes the command to follow and files with a commandline line, instead of subfilenames. For files, one line is printed per remote execution subfile it references. nodename is truncated at seven characters, username at eight, and commandline at how- ever much fits on one line. If is given, for each file with no remote execution files, the command instead shows the meaning of the file itself on one or more lines. Each line consists of a username, then (receive) or (send), then the name of the file to be transferred. See below for details. Filenames are listed in ascending collation order within each section (see Environment Variables below), except that the first section is only sorted by the control filename. Every file in the directory except and appears exactly once in the entire list, unless is used. Details Transaction files are those whose names start with or Subfilenames, which usually start with are gleaned from control file lines, at most one per line, from blank-separated fields, as follows: C.*: R <remotefrom> <localto> <user> -<options> C.*: S <localfrom> <remoteto> <user> -<options> <subfile> <mode> X.*: F <subfile> Lines that do not begin with the appropriate character or are ignored. In the (receive) case, <remotefrom> is used to print the meaning, and its transaction size is taken as zero (unknown). In the (send) case, if <subfile> is <localfrom> is a file not in the spool directory, resulting from a typical call without the (copy) option. In this case <localfrom> is used for the transaction size, if stat-able, and to print the meaning. and both set <subfile> to a true (spooled) subfile name. Orphan files are those whose names start with and which are not referenced by any control files. This algorithm extracts from control files the names of all subfiles that should exist in the spool directory when the transaction is not being actively processed. It is not unusual to see "missing subfiles" and "orphans" if you a spool directory while or is active. Meanings information is obtained by reading each subfile referenced by each file, and by reading files. is taken from the last line in the file which is of the form: U <username> <nodename> Likewise, commandline is taken from the last line of the form: C <commandline> If a subfile name is referenced more than once, references after the first show the subfile as missing. If a subfile name appears in a (corrupt) directory more than once, the name is only found once, but then it is listed again under EXTERNAL INFLUENCES
Environment Variables determines the order in which the output is sorted. If is not specified in the environment or is set to the empty string, the value of is used as a default. If is not specified or is set to the empty string, a default of ``C'' (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to ``C'' (see environ(5)). DIAGNOSTICS
The program writes an appropriate message to standard error if it has any problems dealing with a specified file (directory), including failure to get heap space. It always returns zero as its exit value. If a control file is unopenable (wrong permissions or it disappeared while was running), its name is preceded by a and the size of the transaction is zero. If a subfile is missing (filename not found in the directory being listed) or not stat-able (if required for or its name is preceded by a and it contributes zero bytes to the size of the transaction. If is specified and a file is missing or unreadable, its name is given with a prefixed, as usual. BUGS
This command uses chdir(2) to change to each directory in turn. If more than one is specified, the second through last directories must be absolute (not relative) pathnames, or the may fail. WARNINGS
Use of commands, including is discouraged because they are targeted for removal from HP-UX. Use ftp(1) or rcp(1) instead. AUTHOR
was developed by HP. SEE ALSO
mail(1), uucp(1), uuto(1), uux(1), uuxqt(1M), stat(2). TO BE OBSOLETED uuls(1M)
All times are GMT -4. The time now is 08:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy